Skip to content

Commit

Permalink
consolidate logic for retention for completed jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
timgit committed Mar 31, 2020
1 parent 4af58b1 commit 015940a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/plans.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ const retryStartAfterCase = `CASE
* interval '1'
END`

const keepUntilInheritance = 'keepUntil + (keepUntil - startAfter)'

function completeJobs (schema) {
return `
WITH results AS (
Expand All @@ -260,7 +262,7 @@ function completeJobs (schema) {
SELECT
'${completedJobPrefix}' || name,
${buildJsonCompletionObject(true)},
keepUntil + (keepUntil - startAfter)
${keepUntilInheritance}
FROM results
WHERE NOT name LIKE '${completedJobPrefix}%'
RETURNING 1
Expand All @@ -286,7 +288,7 @@ function failJobs (schema) {
SELECT
'${completedJobPrefix}' || name,
${buildJsonCompletionObject(true)},
keepUntil + (keepUntil - startAfter)
${keepUntilInheritance}
FROM results
WHERE state = '${states.failed}'
AND NOT name LIKE '${completedJobPrefix}%'
Expand All @@ -312,7 +314,7 @@ function expire (schema) {
SELECT
'${completedJobPrefix}' || name,
${buildJsonCompletionObject()},
keepUntil + (keepUntil - startAfter)
${keepUntilInheritance}
FROM results
WHERE state = '${states.expired}'
AND NOT name LIKE '${completedJobPrefix}%'
Expand Down

0 comments on commit 015940a

Please sign in to comment.