Skip to content

Commit

Permalink
Merge pull request #2319 from opengovern/fix-tasks
Browse files Browse the repository at this point in the history
Fix tasks
  • Loading branch information
artaasadi authored Dec 27, 2024
2 parents 74121f6 + c260f54 commit 837cd9d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion services/inventory/http_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1113,9 +1113,12 @@ func (h *HttpHandler) RunQueryByID(ctx echo.Context) error {
if err := bindValidate(ctx, &req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}
if req.ID == "" || req.Type == "" {
if req.ID == "" {
return echo.NewHTTPError(http.StatusBadRequest, "Runnable Type and ID should be provided")
}
if req.Type == "" {
req.Type = "namedquery"
}

newCtx, cancel := context.WithTimeout(ctx.Request().Context(), 30*time.Second)
defer cancel()
Expand Down
10 changes: 5 additions & 5 deletions services/tasks/scheduler/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s *TaskScheduler) runPublisher(ctx context.Context) error {
params, err := JSONBToMap(run.Params)
if err != nil {
result := pgtype.JSONB{}
_ = result.Set([]byte(""))
_ = result.Set([]byte("{}"))
_ = s.db.UpdateTaskRun(run.ID, models.TaskRunStatusFailed, result, "failed to get params")
s.logger.Error("failed to get params", zap.Error(err), zap.Uint("runId", run.ID))
return err
Expand All @@ -55,7 +55,7 @@ func (s *TaskScheduler) runPublisher(ctx context.Context) error {
reqJson, err := json.Marshal(req)
if err != nil {
result := pgtype.JSONB{}
_ = result.Set([]byte(""))
_ = result.Set([]byte("{}"))
_ = s.db.UpdateTaskRun(run.ID, models.TaskRunStatusFailed, result, "failed to marshal run")
s.logger.Error("failed to marshal Task Run", zap.Error(err), zap.Uint("runId", run.ID))
return err
Expand All @@ -73,21 +73,21 @@ func (s *TaskScheduler) runPublisher(ctx context.Context) error {
_, err = s.jq.Produce(ctx, s.NatsConfig.Topic, reqJson, fmt.Sprintf("run-%d", run.ID))
if err != nil {
result := pgtype.JSONB{}
_ = result.Set([]byte(""))
_ = result.Set([]byte("{}"))
_ = s.db.UpdateTaskRun(run.ID, models.TaskRunStatusFailed, result, err.Error())
s.logger.Error("failed to send run", zap.Error(err), zap.Uint("runId", run.ID))
continue
}
} else {
result := pgtype.JSONB{}
_ = result.Set([]byte(""))
_ = result.Set([]byte("{}"))
_ = s.db.UpdateTaskRun(run.ID, models.TaskRunStatusFailed, result, err.Error())
s.logger.Error("failed to send run", zap.Error(err), zap.Uint("runId", run.ID), zap.String("error message", err.Error()))
continue
}
} else {
result := pgtype.JSONB{}
_ = result.Set([]byte(""))
_ = result.Set([]byte("{}"))
_ = s.db.UpdateTaskRun(run.ID, models.TaskRunStatusQueued, result, "")
}
}
Expand Down

0 comments on commit 837cd9d

Please sign in to comment.