Skip to content

Commit

Permalink
fix: change taskrun result type
Browse files Browse the repository at this point in the history
  • Loading branch information
artaasadi committed Dec 27, 2024
1 parent b3cff39 commit 166036a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
5 changes: 2 additions & 3 deletions services/tasks/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down
3 changes: 2 additions & 1 deletion services/tasks/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package db

import (
"fmt"
"github.com/jackc/pgtype"
"github.com/opengovern/opencomply/services/tasks/db/models"
"gorm.io/gorm"
)
Expand Down Expand Up @@ -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,
})
Expand Down
3 changes: 1 addition & 2 deletions services/tasks/db/models/task_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type TaskRun struct {
TaskID string
Params pgtype.JSONB
Status TaskRunStatus
Result string
Result pgtype.JSONB
FailureMessage string
}

Expand All @@ -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,
}
}
2 changes: 0 additions & 2 deletions services/tasks/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -20,7 +19,6 @@ type httpRoutes struct {

platformPrivateKey *rsa.PrivateKey
db db.Database
mainScheduler *scheduler.MainScheduler
}

func (r *httpRoutes) Register(e *echo.Echo) {
Expand Down
8 changes: 6 additions & 2 deletions services/tasks/scheduler/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 166036a

Please sign in to comment.