Started Schedule cloud integration

This commit is contained in:
frikky
2020-11-07 11:45:46 +01:00
parent 1193cf6aaf
commit b72e436d8e
4 changed files with 100 additions and 26 deletions
+2 -1
View File
@@ -279,6 +279,7 @@ type ScheduleOld struct {
CreationTime int64 `json:"creationtime" datastore:"creationtime,noindex"`
LastModificationtime int64 `json:"lastmodificationtime" datastore:"lastmodificationtime,noindex"`
LastRuntime int64 `json:"lastruntime" datastore:"lastruntime,noindex"`
Frequency string `json:"frequency" datastore:"frequency,noindex"`
}
// Returned from /GET /schedules
@@ -3695,7 +3696,7 @@ func handleNewHook(resp http.ResponseWriter, request *http.Request) {
err = executeCloudAction(action, org.SyncConfig.Apikey)
if err != nil {
log.Printf("Failed cloud action START execution", err)
log.Printf("Failed cloud action START execution: %s", err)
resp.WriteHeader(401)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "%s"}`, err)))
return
+40
View File
@@ -318,6 +318,7 @@ type Schedule struct {
ExecutionArgument string `json:"execution_argument" datastore:"execution_argument,noindex"`
Id string `json:"id" datastore:"id"`
OrgId string `json:"org_id" datastore:"org_id"`
Environment string `json:"environment" datastore:"environment"`
}
type Workflow struct {
@@ -3305,6 +3306,45 @@ func scheduleWorkflow(resp http.ResponseWriter, request *http.Request) {
}
}
if schedule.Environment == "cloud" {
log.Printf("[INFO] Should START a cloud schedule for workflow %s with schedule ID %s", workflow.ID, schedule.Id)
// https://shuffler.io/v1/hooks/webhook_80184973-3e82-4852-842e-0290f7f34d7c
org, err := getOrg(ctx, user.ActiveOrg.Id)
if err != nil {
log.Printf("Failed finding org %s: %s", org.Id, err)
return
}
// 1 = scheduleId
// 2 = schedule (cron, frequency)
// 3 = workflowId
// 4 = execution argument
action := CloudSyncJob{
Type: "schedule",
Action: "start",
OrgId: org.Id,
PrimaryItemId: schedule.Id,
SecondaryItem: schedule.Frequency,
ThirdItem: workflow.ID,
FourthItem: schedule.ExecutionArgument,
}
log.Printf("Action: %#v", action)
err = executeCloudAction(action, org.SyncConfig.Apikey)
if err != nil {
log.Printf("Failed cloud action START schedule", err)
resp.WriteHeader(401)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "%s"}`, err)))
return
} else {
log.Printf("Successfully set up cloud action schedule")
resp.WriteHeader(200)
resp.Write([]byte(fmt.Sprintf(`{"success": true, "reason": "Done"}`)))
return
}
}
log.Printf("Schedulearg: %s", parsedBody)
err = createSchedule(