From bbba62e318a8b5d13a86469ac4dfe0b24a0af205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Cie=C5=9Blak?= Date: Wed, 20 Nov 2024 16:36:20 +0100 Subject: [PATCH] wip --- pkg/resources/task.go | 28 +++++++++---------- pkg/resources/task_state_upgraders.go | 16 +++++------ pkg/sdk/testint/tasks_gen_integration_test.go | 4 +-- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/pkg/resources/task.go b/pkg/resources/task.go index 57465dc1ec2..c25d4574007 100644 --- a/pkg/resources/task.go +++ b/pkg/resources/task.go @@ -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 diff --git a/pkg/resources/task_state_upgraders.go b/pkg/resources/task_state_upgraders.go index da1566a1bdc..e02512dd300 100644 --- a/pkg/resources/task_state_upgraders.go +++ b/pkg/resources/task_state_upgraders.go @@ -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") } diff --git a/pkg/sdk/testint/tasks_gen_integration_test.go b/pkg/sdk/testint/tasks_gen_integration_test.go index 5fee5e5bcf0..517cbe8f9c4 100644 --- a/pkg/sdk/testint/tasks_gen_integration_test.go +++ b/pkg/sdk/testint/tasks_gen_integration_test.go @@ -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). @@ -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).