Skip to content
Snippets Groups Projects
Commit 578f0403 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Change monq to agenda

parent f29b160c
No related branches found
No related tags found
1 merge request!116Release v1.0.0
Pipeline #
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
"test": "cd build && mocha" "test": "cd build && mocha"
}, },
"dependencies": { "dependencies": {
"agenda": "^0.9.1",
"apicache": "0.7.0", "apicache": "0.7.0",
"bcrypt-nodejs": "0.0.3", "bcrypt-nodejs": "0.0.3",
"body-parser": "^1.13.1", "body-parser": "^1.13.1",
...@@ -34,7 +35,6 @@ ...@@ -34,7 +35,6 @@
"mocha": "^3.1.2", "mocha": "^3.1.2",
"monetdb-pool": "0.0.8", "monetdb-pool": "0.0.8",
"mongoose": "^4.6.0", "mongoose": "^4.6.0",
"monq": "^0.3.7",
"nconf": "^0.8.x", "nconf": "^0.8.x",
"passport": "^0.3.2", "passport": "^0.3.2",
"squel": "^5.4.2", "squel": "^5.4.2",
......
...@@ -53,45 +53,29 @@ regionApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { ...@@ -53,45 +53,29 @@ regionApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
next(); next();
}, query, response('region')); }, query, response('region'));
const monq = require('monq');
const config = require(`${libs}/config`); const config = require(`${libs}/config`);
const client = monq(config.monq.uri); const Agenda = require('agenda');
const queue = client.queue('db_download'); let agenda = new Agenda({
const execQuery = require(`${libs}/db/query_exec`); db: {
address: config.monq.uri,
const worker = client.worker(['db_download']); collection: 'agendaJobs'}
worker.register({
download: function(query, callback) {
console.log('POPEPO');
console.log(query);
execQuery(query.text, query.values).then((result) => {
if(result.length == 0) {
callback({err: 'No results found'});
return;
}
callback(null, result);
}, (error) => {
callback(error);
});
}
}); });
worker.start(); agenda.define('download region', (job, done) => {
log.debug('POPEPO');
console.log('POPEPO');
console.log(job.attrs.data.sql);
done();
});
worker.on('complete', function (data) { console.log('DATA'); console.log(data); }); agenda.on('ready', function() {
agenda.start();
});
regionApp.get('/download', (req, res) => { regionApp.get('/download', (req, res) => {
req.sql.from('regiao').field('*'); req.sql.from('regiao').field('*');
let params = req.sql.toParam(); let params = req.sql.toParam();
queue.enqueue('download', params, (err, result) => { agenda.now('download region', {sql: params});
log.debug('PEPO');
if(err) {
log.debug('ERRO');
log.debug(err);
}
log.debug(result);
});
res.json({msg: 'Wait for it...'}); res.json({msg: 'Wait for it...'});
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment