Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Nov 20, 2024
1 parent 6e67976 commit bbba62e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
28 changes: 13 additions & 15 deletions pkg/resources/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,23 +609,21 @@ func ReadTask(withExternalChangesMarking bool) schema.ReadContextFunc {
func() error {
if len(task.Schedule) > 0 {
taskSchedule, err := sdk.ParseTaskSchedule(task.Schedule)

if err != nil {
return err
} else if taskSchedule != nil {
switch {
case len(taskSchedule.Cron) > 0:
if err := d.Set("schedule", []any{map[string]any{
"using_cron": taskSchedule.Cron,
}}); err != nil {
return err
}
case taskSchedule.Minutes > 0:
if err := d.Set("schedule", []any{map[string]any{
"minutes": taskSchedule.Minutes,
}}); err != nil {
return err
}
}
switch {
case len(taskSchedule.Cron) > 0:
if err := d.Set("schedule", []any{map[string]any{
"using_cron": taskSchedule.Cron,
}}); err != nil {
return err
}
case taskSchedule.Minutes > 0:
if err := d.Set("schedule", []any{map[string]any{
"minutes": taskSchedule.Minutes,
}}); err != nil {
return err
}
}
return nil
Expand Down
16 changes: 7 additions & 9 deletions pkg/resources/task_state_upgraders.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@ func v098TaskStateUpgrader(ctx context.Context, rawState map[string]any, meta an
if rawState["schedule"] != nil && len(rawState["schedule"].(string)) > 0 {
taskSchedule, err := sdk.ParseTaskSchedule(rawState["schedule"].(string))
scheduleMap := make(map[string]any)

if err != nil {
return nil, err
} else if taskSchedule != nil {
switch {
case len(taskSchedule.Cron) > 0:
scheduleMap["using_cron"] = taskSchedule.Cron
case taskSchedule.Minutes > 0:
scheduleMap["minutes"] = taskSchedule.Minutes
}
rawState["schedule"] = []any{scheduleMap}
}
switch {
case len(taskSchedule.Cron) > 0:
scheduleMap["using_cron"] = taskSchedule.Cron
case taskSchedule.Minutes > 0:
scheduleMap["minutes"] = taskSchedule.Minutes
}
rawState["schedule"] = []any{scheduleMap}
} else {
delete(rawState, "schedule")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/sdk/testint/tasks_gen_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func TestInt_Tasks(t *testing.T) {
err := client.Tasks.CreateOrAlter(ctx, sdk.NewCreateOrAlterTaskRequest(id, sql).
WithWarehouse(*sdk.NewCreateTaskWarehouseRequest().WithWarehouse(testClientHelper().Ids.WarehouseId())).
WithSchedule("10 MINUTES").
WithConfig(`$${"output_dir": "/temp/test_directory/", "learning_rate": 0.1}$$`).
WithConfig(`{"output_dir": "/temp/test_directory/", "learning_rate": 0.1}`).
WithAllowOverlappingExecution(true).
WithUserTaskTimeoutMs(10).
WithSessionParameters(sessionParametersSet).
Expand Down Expand Up @@ -617,7 +617,7 @@ func TestInt_Tasks(t *testing.T) {
WithErrorIntegration(errorIntegration.ID()).
WithSessionParameters(sessionParametersSet).
WithSchedule("10 MINUTE").
WithConfig(`$${"output_dir": "/temp/test_directory/", "learning_rate": 0.1}$$`).
WithConfig(`{"output_dir": "/temp/test_directory/", "learning_rate": 0.1}`).
WithAllowOverlappingExecution(true).
WithUserTaskTimeoutMs(1000).
WithSuspendTaskAfterNumFailures(100).
Expand Down

0 comments on commit bbba62e

Please sign in to comment.