Skip to content

Commit

Permalink
fix: handle empty result in task
Browse files Browse the repository at this point in the history
  • Loading branch information
artaasadi committed Dec 27, 2024
1 parent b34f299 commit 05f5d33
Showing 1 changed file with 5 additions and 5 deletions.
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 05f5d33

Please sign in to comment.