Skip to content

Commit

Permalink
cyverse-de#129: fixed a bug where the SQL statement to mark job statu…
Browse files Browse the repository at this point in the history
…s updates for non-existent jobs as propagated was being rolled back
  • Loading branch information
slr71 committed Oct 30, 2018
1 parent 767374f commit 409561b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
10 changes: 9 additions & 1 deletion src/apps/persistence/jobs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,14 @@
(defn mark-job-status-updates-propagated
"Marks a set of job status updates as propagated."
[ids]
(when (seq ids)
(sql/update :job_status_updates
(set-fields {:propagated true})
(where {:id [in ids]}))))

(defn mark-job-status-updates-for-external-id-completed
"Marks all job status updates for an external ID as completed."
[external-id]
(sql/update :job_status_updates
(set-fields {:propagated true})
(where {:id [in ids]})))
(where {:external_id external-id})))
7 changes: 3 additions & 4 deletions src/apps/service/apps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,11 @@

(defn update-job-status
([external-id]
(jobs/validate-job-status-update-step-count external-id)
(transaction
(let [updates (jp/get-job-status-updates external-id)
steps (jp/get-job-steps-by-external-id external-id)]
(let [updates (jp/get-job-status-updates external-id)]
(when (seq updates)
(jobs/validate-job-status-update-step-count external-id updates steps)
(let [job-id (:job_id (first steps))
(let [job-id (:job_id (jp/get-job-steps-by-external-id external-id))
job-step (jobs/lock-job-step job-id external-id)
job (jobs/lock-job job-id)
batch (when-let [parent-id (:parent_id job)] (jp/get-job-by-id parent-id))
Expand Down
17 changes: 9 additions & 8 deletions src/apps/service/apps/jobs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
(defn validate-job-status-update-step-count
"Validates the number of steps for an external ID provided in a set of job status updates. If there are too many or
too few matching job steps then all of the job status updates will be marked as propagated and an exception will be
thrown."
[external-id updates job-steps]
(when (empty? job-steps)
(jp/mark-job-status-updates-propagated (mapv :id updates))
(service/not-found "job step" external-id))
(when (> (count job-steps) 1)
(jp/mark-job-status-updates-propagated (mapv :id updates))
(service/not-unique "job step" external-id)))
thrown. This function should not be called from within a transaction."
[external-id]
(let [job-steps (jp/get-job-steps-by-external-id external-id)]
(when (empty? job-steps)
(jp/mark-job-status-updates-for-external-id-completed external-id)
(service/not-found "job step" external-id))
(when (> (count job-steps) 1)
(jp/mark-job-status-updates-for-external-id-completed external-id)
(service/not-unique "job step" external-id))))

(defn lock-job-step
[job-id external-id]
Expand Down

0 comments on commit 409561b

Please sign in to comment.