From 6919245036fdfdf6a6d0b6826863a43bd3208e48 Mon Sep 17 00:00:00 2001 From: Cassio Cabral Date: Wed, 2 Sep 2015 12:15:16 -0300 Subject: [PATCH] adiciona a url de limpar fila --- endpoints/ios.js | 2 +- endpoints/texto.js | 2 +- helpers/core.js | 2 +- logsystem/main.coffee | 1 + logsystem/main.js | 6 ++++++ server.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 logsystem/main.coffee create mode 100644 logsystem/main.js diff --git a/endpoints/ios.js b/endpoints/ios.js index 88b12ae..292e181 100644 --- a/endpoints/ios.js +++ b/endpoints/ios.js @@ -38,7 +38,7 @@ function init(req, res) { var job = queue.create('exec_command_line', { title: 'Command Line for: ' + req.body.servico, command_line: command_line - }).save(); + }).removeOnComplete( true ).save(); queue.process('exec_command_line', function(job, done){ child = queue_helper.exec_command_line(job.data.command_line, done); diff --git a/endpoints/texto.js b/endpoints/texto.js index 25d54df..5d31175 100755 --- a/endpoints/texto.js +++ b/endpoints/texto.js @@ -50,7 +50,7 @@ function init(req, res, Request) { var job = queue.create('exec_command_line', { title: 'Command Line for: ' + req.body.servico, command_line: command_line - }).save(); + }).removeOnComplete( true ).save(); queue.process('exec_command_line', function(job, done){ child = queue_helper.exec_command_line(job.data.command_line, done); diff --git a/helpers/core.js b/helpers/core.js index a1e61b0..c5c9627 100644 --- a/helpers/core.js +++ b/helpers/core.js @@ -21,7 +21,7 @@ function call(id, command_line, req, res) { job = queue.create('exec_command_line', { title: 'Command Line for: ' + req.body.servico, command_line: command_line - }).save(); + }).removeOnComplete( true ).save(); queue.process('exec_command_line', function(job, done){ child = queue_helper.exec_command_line(job.data.command_line, done); diff --git a/logsystem/main.coffee b/logsystem/main.coffee new file mode 100644 index 0000000..be62540 --- /dev/null +++ b/logsystem/main.coffee @@ -0,0 +1 @@ +config = require('./config/main.js') diff --git a/logsystem/main.js b/logsystem/main.js new file mode 100644 index 0000000..43abdaf --- /dev/null +++ b/logsystem/main.js @@ -0,0 +1,6 @@ +(function() { + var config; + + config = require('./config/main.js'); + +}).call(this); diff --git a/server.js b/server.js index 7162a08..6ee357c 100755 --- a/server.js +++ b/server.js @@ -16,6 +16,8 @@ var app = express(); var Request = require('./db/schemas/request').init(mongoose); var db = require('./db/api'); var config = require('./config/main.js'); +var kue = require('kue'); +var queue = kue.createQueue(); app.use(express.static(path.join(__dirname, '/videos'))); app.use(express.bodyParser({ keepExtensions: true, uploadDir: path.join(__dirname, '/uploads') })); @@ -90,6 +92,60 @@ app.post('/glosa', function(req, res) { }); }); +app.get('/limparfila', function(req, res) { + + // graceful shutdown + process.once( 'SIGTERM', function ( sig ) { + queue.shutdown( 5000, function(err) { + console.log( 'Kue shutdown: ', err||'' ); + process.exit( 0 ); + }); + }); + + // todos abaixos sao redundantes + queue.inactive( function( err, ids ) { + ids.forEach( function( id ) { + kue.Job.get( id, function( err, job ) { + job.remove( function(){ + // console.log( 'removed ', job.id ); + }); + }); + }); + }); + + queue.active( function( err, ids ) { + ids.forEach( function( id ) { + kue.Job.get( id, function( err, job ) { + job.remove( function(){ + // console.log( 'removed ', job.id ); + }); + }); + }); + }); + + queue.complete( function( err, ids ) { + ids.forEach( function( id ) { + kue.Job.get( id, function( err, job ) { + job.remove( function(){ + // console.log( 'removed ', job.id ); + }); + }); + }); + }); + + queue.failed( function( err, ids ) { + ids.forEach( function( id ) { + kue.Job.get( id, function( err, job ) { + job.remove( function(){ + // console.log( 'removed ', job.id ); + }); + }); + }); + }); + + res.send(200, "Fila limpa"); +}); + app.listen(properties.port, properties.host, function(){ console.log('Server running on ' + properties.host + ':' + properties.port); }); -- libgit2 0.21.2