diff --git a/js/modules/attachment_downloads.js b/js/modules/attachment_downloads.js index 91e6cb18f6..8600c0eb33 100644 --- a/js/modules/attachment_downloads.js +++ b/js/modules/attachment_downloads.js @@ -135,11 +135,17 @@ async function _maybeStartJob() { const jobCount = getActiveJobCount(); const limit = MAX_ATTACHMENT_JOB_PARALLELISM - jobCount; if (limit <= 0) { + logger.info( + 'attachment_downloads/_maybeStartJob: reached active job limit, waiting' + ); return; } const nextJobs = await getNextAttachmentDownloadJobs(limit); if (nextJobs.length <= 0) { + logger.info( + 'attachment_downloads/_maybeStartJob: no attachment jobs to run' + ); return; } @@ -148,10 +154,19 @@ async function _maybeStartJob() { const secondJobCount = getActiveJobCount(); const needed = MAX_ATTACHMENT_JOB_PARALLELISM - secondJobCount; if (needed <= 0) { + logger.info( + 'attachment_downloads/_maybeStartJob: reached active job limit after ' + + 'db query, waiting' + ); return; } 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) { const job = jobs[i]; const existing = _activeAttachmentDownloadJobs[job.id]; diff --git a/ts/sql/Server.ts b/ts/sql/Server.ts index b6458b34b5..157bf8388d 100644 --- a/ts/sql/Server.ts +++ b/ts/sql/Server.ts @@ -4249,7 +4249,7 @@ async function getNextAttachmentDownloadJobs( ` SELECT json FROM attachment_downloads - WHERE pending = 0 AND timestamp < $timestamp + WHERE pending = 0 AND timestamp <= $timestamp ORDER BY timestamp DESC LIMIT $limit; `