Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var email = {
to: decodeURI(urlParts[1]),
subject: decodeURI(urlParts[2]),
text: decodeURI(urlParts[3]),
};
queue.enqueue('emailQueue', "sendEmail", email, function(error){
console.log('email :' + JSON.stringify(email));
if(error){ console.log(error) }
var response = {email: email};
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify(response, null, 2));
});
};
var queue = new NR.queue({connection: connectionDetails}, jobs);
queue.connect(function(){
http.createServer(server).listen(httpPort, httpHost);
console.log('Server running at ' + httpHost + ':' + httpPort);
console.log('send an email and message to /TO_ADDRESS/SUBJECT/YOUR_MESSAGE');
});
///////////////////
// RESQUE WORKER //
///////////////////
var worker = new NR.worker({connection: connectionDetails, queues: ['emailQueue']}, jobs);
worker.connect(function(){
worker.workerCleanup();
worker.start();
});
"slowCPUJob": {
plugins: [],
pluginOptions: {},
perform: function(callback){
var start = new Date().getTime();
blockingSleep(1000);
callback(null, (new Date().getTime() - start) );
},
},
};
///////////////////
// ENQUEUE TASKS //
///////////////////
var queue = new NR.queue({connection: connectionDetails}, jobs);
queue.connect(function(){
var i;
i = 0;
while(i < 10){
queue.enqueue('slowQueue', "slowCPUJob", []);
i++;
}
i = 0;
while(i < 500){
queue.enqueue('slowQueue', "slowSleepJob", []);
i++;
}
});
//////////
var log = options.log
var work = new Work(options)
if (!options.connection) {
return {
enqueue: function (foo, bar, job) {
doLocal(work, job)
},
removeFailed: function () {},
failed: function () {},
length: function () {},
allWorkingOn: function () {}
}
}
var connection = work.connection
connection.pkg = 'redis'
var queue = new Resque({connection: connection}, work.jobs)
process.on('SIGINT', function () {
queue.end(function () {
process.exit()
})
})
process.on('SIGTERM', function () {
queue.end(function () {
process.exit()
})
})
queue.connect(function () {
setInterval(function () {
log.info('Clearing old workers from the queue')
const connect = async redis => {
if (!queue) {
queue = new NR.queue({ connection: { redis: redis } }, tasks)
await queue.connect()
}
return queue
}