Prevent multiple instances of same background attachment job

This commit is contained in:
Scott Nonnenberg 2019-09-17 14:09:01 -07:00
parent 368d5b7e4b
commit 3719724337

View file

@ -146,9 +146,14 @@ async function _maybeStartJob() {
const jobs = nextJobs.slice(0, Math.min(needed, nextJobs.length));
for (let i = 0, max = jobs.length; i < max; i += 1) {
const job = jobs[i];
const existing = _activeAttachmentDownloadJobs[job.id];
if (existing) {
logger.warn(`_maybeStartJob: Job ${job.id} is already running`);
} else {
_activeAttachmentDownloadJobs[job.id] = _runJob(job);
}
}
}
async function _runJob(job) {
const { id, messageId, attachment, type, index, attempts } = job || {};