(_ context.Context, jobID int64, entityID string)
| 248 | } |
| 249 | |
| 250 | func (s *sqlDatabase) UnlockJob(_ context.Context, jobID int64, entityID string) error { |
| 251 | var asParams params.Job |
| 252 | |
| 253 | err := s.conn.Transaction(func(tx *gorm.DB) error { |
| 254 | var workflowJob WorkflowJob |
| 255 | q := tx.Clauses(clause.Locking{Strength: "UPDATE"}).Where("workflow_job_id = ?", jobID).First(&workflowJob) |
| 256 | |
| 257 | if q.Error != nil { |
| 258 | if errors.Is(q.Error, gorm.ErrRecordNotFound) { |
| 259 | return runnerErrors.ErrNotFound |
| 260 | } |
| 261 | return fmt.Errorf("error fetching job: %w", q.Error) |
| 262 | } |
| 263 | |
| 264 | if workflowJob.LockedBy == uuid.Nil { |
| 265 | // Job is already unlocked. |
| 266 | return nil |
| 267 | } |
| 268 | |
| 269 | if workflowJob.LockedBy != uuid.Nil && workflowJob.LockedBy.String() != entityID { |
| 270 | return runnerErrors.NewConflictError("job is locked by another entity %s", workflowJob.LockedBy.String()) |
| 271 | } |
| 272 | |
| 273 | workflowJob.LockedBy = uuid.Nil |
| 274 | if err := tx.Save(&workflowJob).Error; err != nil { |
| 275 | return fmt.Errorf("error saving job: %w", err) |
| 276 | } |
| 277 | |
| 278 | var err error |
| 279 | asParams, err = sqlWorkflowJobToParamsJob(workflowJob) |
| 280 | if err != nil { |
| 281 | return fmt.Errorf("error converting job: %w", err) |
| 282 | } |
| 283 | return nil |
| 284 | }) |
| 285 | if err != nil { |
| 286 | return err |
| 287 | } |
| 288 | |
| 289 | if asParams.ID != 0 { |
| 290 | s.sendNotify(common.JobEntityType, common.UpdateOperation, asParams) |
| 291 | } |
| 292 | return nil |
| 293 | } |
| 294 | |
| 295 | func (s *sqlDatabase) CreateOrUpdateJob(ctx context.Context, job params.Job) (params.Job, error) { |
| 296 | var asParams params.Job |
nothing calls this directly
no test coverage detected