Prioritize tasks that have never run at all

master
Sven Slootweg 2 years ago
parent e40113a701
commit 48e9f8372b

@ -60,29 +60,34 @@ function makeFillQuery(withDependencies) {
SELECT item_id FROM tag_candidates
`
}
),
tasks AS NOT MATERIALIZED (
SELECT
item_id,
is_successful,
(
results.is_successful = FALSE
OR (
results.is_successful = TRUE
AND results.is_invalidated = FALSE
AND (
results.expires_at > NOW()
OR results.expires_at IS NULL
)
)
) AS is_completed
FROM srap_task_results AS results
WHERE
results.task = :task
AND results.task_version = :taskVersion
)
SELECT
:task AS task,
item_id
full_candidates.item_id
FROM full_candidates
WHERE NOT EXISTS (
SELECT item_id FROM srap_task_results AS results
WHERE
item_id = full_candidates.item_id
AND results.task = :task
AND results.task_version = :taskVersion
AND (
results.is_successful = FALSE
OR (
results.is_successful = TRUE
AND results.is_invalidated = FALSE
AND (
results.expires_at > NOW()
OR results.expires_at IS NULL
)
)
)
)
LEFT JOIN tasks ON full_candidates.item_id = tasks.item_id
WHERE tasks.is_completed IS NOT TRUE
ORDER BY tasks.is_successful NULLS FIRST
`;
}

Loading…
Cancel
Save