Created
December 7, 2020 16:14
-
-
Save aatifbandey/9a161cc7be02cf9e5ff586bdf34d5055 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Redis = require("ioredis"); | |
const redis = new Redis({ | |
host: "localhost", | |
port: 3000, | |
keyPrefix: "cache", | |
logName: "html-redis", | |
}); | |
const Warlock = require('node-redis-warlock'); | |
const warlock = new Warlock(redis); | |
function executeOnce(key, callback, typeOf) { | |
warlock.lock(key, 20000, function(err, unlock) { | |
if (err) { | |
// Something went wrong and we weren't able to set a lock | |
return; | |
} | |
if (typeof unlock === 'function') { | |
setTimeout(function() { | |
callback(unlock, typeOf); | |
}, 1500); | |
} | |
}); | |
} | |
new CronJob({ | |
cronTime: '*/30 * * * *', | |
onTick: function() { | |
executeOnce('every-oneday-lock', runCron); | |
}, | |
start: true, | |
timeZone: 'Asia/Jakarta', | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment