Skip to content

Instantly share code, notes, and snippets.

@aatifbandey
Created December 7, 2020 16:14
Show Gist options
  • Save aatifbandey/9a161cc7be02cf9e5ff586bdf34d5055 to your computer and use it in GitHub Desktop.
Save aatifbandey/9a161cc7be02cf9e5ff586bdf34d5055 to your computer and use it in GitHub Desktop.
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