@@ -53,16 +53,18 @@ type TasksAPI interface {
53
53
GetTask (ctx context.Context , task * domain.Task ) (* domain.Task , error )
54
54
// GetTaskByID retrieves a task found using taskID.
55
55
GetTaskByID (ctx context.Context , taskID string ) (* domain.Task , error )
56
- // CreateTask creates a new task according the the task object.
56
+ // CreateTask creates a new task according the task object.
57
57
// It copies OrgId, Name, Description, Flux, Status and Every or Cron properties. Every and Cron are mutually exclusive.
58
58
// Every has higher priority.
59
59
CreateTask (ctx context.Context , task * domain.Task ) (* domain.Task , error )
60
- // CreateTaskWithEvery creates a new task with with the name, flux script and every repetition setting, in the org orgID.
60
+ // CreateTaskWithEvery creates a new task with the name, flux script and every repetition setting, in the org orgID.
61
61
// Every holds duration values.
62
62
CreateTaskWithEvery (ctx context.Context , name , flux , every , orgID string ) (* domain.Task , error )
63
- // CreateTaskWithCron creates a new task with with the name, flux script and cron repetition setting, in the org orgID
63
+ // CreateTaskWithCron creates a new task with the name, flux script and cron repetition setting, in the org orgID
64
64
// Cron holds cron-like setting, e.g. once an hour at beginning of the hour "0 * * * *".
65
65
CreateTaskWithCron (ctx context.Context , name , flux , cron , orgID string ) (* domain.Task , error )
66
+ // CreateTaskByFlux creates a new task with complete definition in flux script, in the org orgID
67
+ CreateTaskByFlux (ctx context.Context , flux , orgID string ) (* domain.Task , error )
66
68
// UpdateTask updates a task.
67
69
// It copies Description, Flux, Status, Offset and Every or Cron properties. Every and Cron are mutually exclusive.
68
70
// Every has higher priority.
@@ -217,37 +219,46 @@ func (t *tasksAPI) createTask(ctx context.Context, taskReq *domain.TaskCreateReq
217
219
return response .JSON201 , nil
218
220
}
219
221
220
- func createTaskReq (name , flux string , every , cron * string , orgID string ) * domain.TaskCreateRequest {
222
+ func createTaskReqDetailed (name , flux string , every , cron * string , orgID string ) * domain.TaskCreateRequest {
221
223
repetition := ""
222
224
if every != nil {
223
225
repetition = fmt .Sprintf ("every: %s" , * every )
224
226
} else if cron != nil {
225
227
repetition = fmt .Sprintf (`cron: "%s"` , * cron )
226
228
}
229
+ fullFlux := fmt .Sprintf (`option task = { name: "%s", %s } %s` , name , repetition , flux )
230
+ return createTaskReq (fullFlux , orgID )
231
+ }
232
+ func createTaskReq (flux string , orgID string ) * domain.TaskCreateRequest {
233
+
227
234
status := domain .TaskStatusTypeActive
228
235
taskReq := & domain.TaskCreateRequest {
229
- Flux : fmt .Sprintf (`option task = { name: "%s", %s }
230
- %s` , name , repetition , flux ),
236
+ Flux : flux ,
231
237
Status : & status ,
232
238
OrgID : & orgID ,
233
239
}
234
240
return taskReq
235
241
}
236
242
237
243
func (t * tasksAPI ) CreateTask (ctx context.Context , task * domain.Task ) (* domain.Task , error ) {
238
- taskReq := createTaskReq (task .Name , task .Flux , task .Every , task .Cron , task .OrgID )
244
+ taskReq := createTaskReqDetailed (task .Name , task .Flux , task .Every , task .Cron , task .OrgID )
239
245
taskReq .Description = task .Description
240
246
taskReq .Status = task .Status
241
247
return t .createTask (ctx , taskReq )
242
248
}
243
249
244
250
func (t * tasksAPI ) CreateTaskWithEvery (ctx context.Context , name , flux , every , orgID string ) (* domain.Task , error ) {
245
- taskReq := createTaskReq (name , flux , & every , nil , orgID )
251
+ taskReq := createTaskReqDetailed (name , flux , & every , nil , orgID )
246
252
return t .createTask (ctx , taskReq )
247
253
}
248
254
249
255
func (t * tasksAPI ) CreateTaskWithCron (ctx context.Context , name , flux , cron , orgID string ) (* domain.Task , error ) {
250
- taskReq := createTaskReq (name , flux , nil , & cron , orgID )
256
+ taskReq := createTaskReqDetailed (name , flux , nil , & cron , orgID )
257
+ return t .createTask (ctx , taskReq )
258
+ }
259
+
260
+ func (t * tasksAPI ) CreateTaskByFlux (ctx context.Context , flux , orgID string ) (* domain.Task , error ) {
261
+ taskReq := createTaskReq (flux , orgID )
251
262
return t .createTask (ctx , taskReq )
252
263
}
253
264
0 commit comments