mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-02-25 08:23:43 +08:00
Updated lock handling
This commit is contained in:
parent
0c7ad4c107
commit
14ecd5cf90
4 changed files with 17 additions and 19 deletions
|
@ -9,7 +9,6 @@ const AcmeChallenge = require('./acme-challenge');
|
|||
const pkg = require('../../package.json');
|
||||
const { normalizeDomain } = require('../tools');
|
||||
const Lock = require('ioredfour');
|
||||
const util = require('util');
|
||||
const log = require('npmlog');
|
||||
const { Resolver } = require('dns').promises;
|
||||
const resolver = new Resolver();
|
||||
|
@ -187,8 +186,8 @@ const acquireCert = async (domain, acmeOptions, certificateData, certHandler) =>
|
|||
redis: db.redis,
|
||||
namespace: 'acme'
|
||||
});
|
||||
getLock = util.promisify(lock.waitAcquireLock.bind(lock));
|
||||
releaseLock = util.promisify(lock.releaseLock.bind(lock));
|
||||
getLock = (...args) => lock.waitAcquireLock(...args);
|
||||
releaseLock = (...args) => lock.releaseLock(...args);
|
||||
}
|
||||
|
||||
let lock = await getLock(domainOpLockKey, 10 * 60 * 1000, 3 * 60 * 1000);
|
||||
|
|
|
@ -84,6 +84,9 @@ module.exports = {
|
|||
|
||||
TASK_LOCK_INTERVAL: 1 * 3600 * 1000,
|
||||
|
||||
// unlock pending tasks in every 2 minutes
|
||||
TASK_RELEASE_DELAYED_INTERVAL: 2 * 60 * 1000,
|
||||
|
||||
// renewal interval, must be lower than TASK_LOCK_INTERVAL
|
||||
TASK_UPDATE_INTERVAL: 10 * 60 * 1000,
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
"html-to-text": "8.0.0",
|
||||
"humanname": "0.2.2",
|
||||
"iconv-lite": "0.6.3",
|
||||
"ioredfour": "1.0.2-ioredis-03",
|
||||
"ioredfour": "1.1.0-ioredis-05",
|
||||
"ioredis": "4.27.6",
|
||||
"ipaddr": "0.1.0",
|
||||
"ipaddr.js": "2.0.1",
|
||||
|
|
24
tasks.js
24
tasks.js
|
@ -448,25 +448,21 @@ function timer(ttl) {
|
|||
}
|
||||
|
||||
async function runTasks() {
|
||||
// first release expired tasks
|
||||
let pendingCheckTime = 0;
|
||||
|
||||
let done = false;
|
||||
log.verbose('Tasks', 'Starting task poll loop');
|
||||
while (!done) {
|
||||
if (Date.now() - pendingCheckTime > consts.TASK_RELEASE_DELAYED_INTERVAL) {
|
||||
// Once in a while release pending tasks
|
||||
try {
|
||||
await taskHandler.releasePending();
|
||||
} catch (err) {
|
||||
log.error('Tasks', 'Failed releasing expired tasks. error=%s', err.message);
|
||||
taskTimeout = setTimeout(runTasks, consts.TASK_STARTUP_INTERVAL);
|
||||
await timer(consts.TASK_STARTUP_INTERVAL);
|
||||
return runTasks();
|
||||
await timer(consts.TASK_IDLE_INTERVAL);
|
||||
} finally {
|
||||
pendingCheckTime = Date.now();
|
||||
}
|
||||
|
||||
let startTime = Date.now();
|
||||
let done = false;
|
||||
log.verbose('Tasks', 'Starting task poll loop');
|
||||
while (!done) {
|
||||
if (Date.now() - startTime > 3600 * 1000) {
|
||||
// Once in a while break the loop, so that pending tasks can be unlocked
|
||||
done = true;
|
||||
log.verbose('Tasks', 'Breaking task poll loop');
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue