diff --git a/services/tasks/cmd.go b/services/tasks/cmd.go index 4fa8e536b..6e2565976 100644 --- a/services/tasks/cmd.go +++ b/services/tasks/cmd.go @@ -101,9 +101,8 @@ func start(ctx context.Context) error { } return httpserver.RegisterAndStart(ctx, logger, cfg.Http.Address, &httpRoutes{ - logger: logger, - db: db, - mainScheduler: mainScheduler, + logger: logger, + db: db, }) } diff --git a/services/tasks/db/db.go b/services/tasks/db/db.go index 413ff1ede..b574168d7 100644 --- a/services/tasks/db/db.go +++ b/services/tasks/db/db.go @@ -2,6 +2,7 @@ package db import ( "fmt" + "github.com/jackc/pgtype" "github.com/opengovern/opencomply/services/tasks/db/models" "gorm.io/gorm" ) @@ -108,7 +109,7 @@ func (db Database) CreateTaskRun(taskRun *models.TaskRun) error { } // UpdateTaskRun creates a task result -func (db Database) UpdateTaskRun(runID uint, status models.TaskRunStatus, result string, failureMessage string) error { +func (db Database) UpdateTaskRun(runID uint, status models.TaskRunStatus, result pgtype.JSONB, failureMessage string) error { tx := db.Orm.Where("id = ?", runID).Updates(&models.TaskRun{ Status: status, Result: result, FailureMessage: failureMessage, }) diff --git a/services/tasks/db/models/task_run.go b/services/tasks/db/models/task_run.go index adc2bbc89..4e3413ec3 100644 --- a/services/tasks/db/models/task_run.go +++ b/services/tasks/db/models/task_run.go @@ -22,7 +22,7 @@ type TaskRun struct { TaskID string Params pgtype.JSONB Status TaskRunStatus - Result string + Result pgtype.JSONB FailureMessage string } @@ -33,7 +33,6 @@ func (tr TaskRun) ToAPI() api.TaskRun { UpdatedAt: tr.UpdatedAt, TaskID: tr.TaskID, Status: string(tr.Status), - Result: tr.Result, FailureMessage: tr.FailureMessage, } } diff --git a/services/tasks/http.go b/services/tasks/http.go index 776c744a6..8a65131e7 100644 --- a/services/tasks/http.go +++ b/services/tasks/http.go @@ -8,7 +8,6 @@ import ( "github.com/opengovern/opencomply/services/tasks/api" "github.com/opengovern/opencomply/services/tasks/db" "github.com/opengovern/opencomply/services/tasks/db/models" - "github.com/opengovern/opencomply/services/tasks/scheduler" "net/http" "github.com/labstack/echo/v4" @@ -20,7 +19,6 @@ type httpRoutes struct { platformPrivateKey *rsa.PrivateKey db db.Database - mainScheduler *scheduler.MainScheduler } func (r *httpRoutes) Register(e *echo.Echo) { diff --git a/services/tasks/scheduler/consumer.go b/services/tasks/scheduler/consumer.go index 9347e584a..675a05a52 100644 --- a/services/tasks/scheduler/consumer.go +++ b/services/tasks/scheduler/consumer.go @@ -31,9 +31,13 @@ func (s *TaskScheduler) RunTaskResponseConsumer(ctx context.Context) error { taskRunUpdate := models.TaskRun{ Status: response.Status, FailureMessage: response.FailureMessage, - Result: string(response.Result), } - err := s.db.UpdateTaskRun(response.RunID, taskRunUpdate.Status, taskRunUpdate.Result, taskRunUpdate.FailureMessage) + err := taskRunUpdate.Result.Set(response.Result) + if err != nil { + s.logger.Error("failed to set result", zap.Error(err)) + return + } + err = s.db.UpdateTaskRun(response.RunID, taskRunUpdate.Status, taskRunUpdate.Result, taskRunUpdate.FailureMessage) if err != nil { s.logger.Error("Failed to update the status of RunTaskResponse", zap.String("Task", s.TaskID),