Simplify attachment jobs SQL query
This commit is contained in:
parent
fcaa34d67a
commit
e4d7e1e9c8
2 changed files with 16 additions and 1 deletions
|
@ -135,11 +135,17 @@ async function _maybeStartJob() {
|
||||||
const jobCount = getActiveJobCount();
|
const jobCount = getActiveJobCount();
|
||||||
const limit = MAX_ATTACHMENT_JOB_PARALLELISM - jobCount;
|
const limit = MAX_ATTACHMENT_JOB_PARALLELISM - jobCount;
|
||||||
if (limit <= 0) {
|
if (limit <= 0) {
|
||||||
|
logger.info(
|
||||||
|
'attachment_downloads/_maybeStartJob: reached active job limit, waiting'
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextJobs = await getNextAttachmentDownloadJobs(limit);
|
const nextJobs = await getNextAttachmentDownloadJobs(limit);
|
||||||
if (nextJobs.length <= 0) {
|
if (nextJobs.length <= 0) {
|
||||||
|
logger.info(
|
||||||
|
'attachment_downloads/_maybeStartJob: no attachment jobs to run'
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,10 +154,19 @@ async function _maybeStartJob() {
|
||||||
const secondJobCount = getActiveJobCount();
|
const secondJobCount = getActiveJobCount();
|
||||||
const needed = MAX_ATTACHMENT_JOB_PARALLELISM - secondJobCount;
|
const needed = MAX_ATTACHMENT_JOB_PARALLELISM - secondJobCount;
|
||||||
if (needed <= 0) {
|
if (needed <= 0) {
|
||||||
|
logger.info(
|
||||||
|
'attachment_downloads/_maybeStartJob: reached active job limit after ' +
|
||||||
|
'db query, waiting'
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const jobs = nextJobs.slice(0, Math.min(needed, nextJobs.length));
|
const jobs = nextJobs.slice(0, Math.min(needed, nextJobs.length));
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
`attachment_downloads/_maybeStartJob: starting ${jobs.length} jobs`
|
||||||
|
);
|
||||||
|
|
||||||
for (let i = 0, max = jobs.length; i < max; i += 1) {
|
for (let i = 0, max = jobs.length; i < max; i += 1) {
|
||||||
const job = jobs[i];
|
const job = jobs[i];
|
||||||
const existing = _activeAttachmentDownloadJobs[job.id];
|
const existing = _activeAttachmentDownloadJobs[job.id];
|
||||||
|
|
|
@ -4249,7 +4249,7 @@ async function getNextAttachmentDownloadJobs(
|
||||||
`
|
`
|
||||||
SELECT json
|
SELECT json
|
||||||
FROM attachment_downloads
|
FROM attachment_downloads
|
||||||
WHERE pending = 0 AND timestamp < $timestamp
|
WHERE pending = 0 AND timestamp <= $timestamp
|
||||||
ORDER BY timestamp DESC
|
ORDER BY timestamp DESC
|
||||||
LIMIT $limit;
|
LIMIT $limit;
|
||||||
`
|
`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue