Commit 6919245036fdfdf6a6d0b6826863a43bd3208e48
1 parent
73435c61
Exists in
master
and in
1 other branch
adiciona a url de limpar fila
Showing
6 changed files
with
66 additions
and
3 deletions
Show diff stats
endpoints/ios.js
@@ -38,7 +38,7 @@ function init(req, res) { | @@ -38,7 +38,7 @@ function init(req, res) { | ||
38 | var job = queue.create('exec_command_line', { | 38 | var job = queue.create('exec_command_line', { |
39 | title: 'Command Line for: ' + req.body.servico, | 39 | title: 'Command Line for: ' + req.body.servico, |
40 | command_line: command_line | 40 | command_line: command_line |
41 | - }).save(); | 41 | + }).removeOnComplete( true ).save(); |
42 | 42 | ||
43 | queue.process('exec_command_line', function(job, done){ | 43 | queue.process('exec_command_line', function(job, done){ |
44 | child = queue_helper.exec_command_line(job.data.command_line, done); | 44 | child = queue_helper.exec_command_line(job.data.command_line, done); |
endpoints/texto.js
@@ -50,7 +50,7 @@ function init(req, res, Request) { | @@ -50,7 +50,7 @@ function init(req, res, Request) { | ||
50 | var job = queue.create('exec_command_line', { | 50 | var job = queue.create('exec_command_line', { |
51 | title: 'Command Line for: ' + req.body.servico, | 51 | title: 'Command Line for: ' + req.body.servico, |
52 | command_line: command_line | 52 | command_line: command_line |
53 | - }).save(); | 53 | + }).removeOnComplete( true ).save(); |
54 | 54 | ||
55 | queue.process('exec_command_line', function(job, done){ | 55 | queue.process('exec_command_line', function(job, done){ |
56 | child = queue_helper.exec_command_line(job.data.command_line, done); | 56 | child = queue_helper.exec_command_line(job.data.command_line, done); |
helpers/core.js
@@ -21,7 +21,7 @@ function call(id, command_line, req, res) { | @@ -21,7 +21,7 @@ function call(id, command_line, req, res) { | ||
21 | job = queue.create('exec_command_line', { | 21 | job = queue.create('exec_command_line', { |
22 | title: 'Command Line for: ' + req.body.servico, | 22 | title: 'Command Line for: ' + req.body.servico, |
23 | command_line: command_line | 23 | command_line: command_line |
24 | - }).save(); | 24 | + }).removeOnComplete( true ).save(); |
25 | 25 | ||
26 | queue.process('exec_command_line', function(job, done){ | 26 | queue.process('exec_command_line', function(job, done){ |
27 | child = queue_helper.exec_command_line(job.data.command_line, done); | 27 | child = queue_helper.exec_command_line(job.data.command_line, done); |
@@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
1 | +config = require('./config/main.js') |
server.js
@@ -16,6 +16,8 @@ var app = express(); | @@ -16,6 +16,8 @@ var app = express(); | ||
16 | var Request = require('./db/schemas/request').init(mongoose); | 16 | var Request = require('./db/schemas/request').init(mongoose); |
17 | var db = require('./db/api'); | 17 | var db = require('./db/api'); |
18 | var config = require('./config/main.js'); | 18 | var config = require('./config/main.js'); |
19 | +var kue = require('kue'); | ||
20 | +var queue = kue.createQueue(); | ||
19 | 21 | ||
20 | app.use(express.static(path.join(__dirname, '/videos'))); | 22 | app.use(express.static(path.join(__dirname, '/videos'))); |
21 | app.use(express.bodyParser({ keepExtensions: true, uploadDir: path.join(__dirname, '/uploads') })); | 23 | app.use(express.bodyParser({ keepExtensions: true, uploadDir: path.join(__dirname, '/uploads') })); |
@@ -90,6 +92,60 @@ app.post('/glosa', function(req, res) { | @@ -90,6 +92,60 @@ app.post('/glosa', function(req, res) { | ||
90 | }); | 92 | }); |
91 | }); | 93 | }); |
92 | 94 | ||
95 | +app.get('/limparfila', function(req, res) { | ||
96 | + | ||
97 | + // graceful shutdown | ||
98 | + process.once( 'SIGTERM', function ( sig ) { | ||
99 | + queue.shutdown( 5000, function(err) { | ||
100 | + console.log( 'Kue shutdown: ', err||'' ); | ||
101 | + process.exit( 0 ); | ||
102 | + }); | ||
103 | + }); | ||
104 | + | ||
105 | + // todos abaixos sao redundantes | ||
106 | + queue.inactive( function( err, ids ) { | ||
107 | + ids.forEach( function( id ) { | ||
108 | + kue.Job.get( id, function( err, job ) { | ||
109 | + job.remove( function(){ | ||
110 | + // console.log( 'removed ', job.id ); | ||
111 | + }); | ||
112 | + }); | ||
113 | + }); | ||
114 | + }); | ||
115 | + | ||
116 | + queue.active( function( err, ids ) { | ||
117 | + ids.forEach( function( id ) { | ||
118 | + kue.Job.get( id, function( err, job ) { | ||
119 | + job.remove( function(){ | ||
120 | + // console.log( 'removed ', job.id ); | ||
121 | + }); | ||
122 | + }); | ||
123 | + }); | ||
124 | + }); | ||
125 | + | ||
126 | + queue.complete( function( err, ids ) { | ||
127 | + ids.forEach( function( id ) { | ||
128 | + kue.Job.get( id, function( err, job ) { | ||
129 | + job.remove( function(){ | ||
130 | + // console.log( 'removed ', job.id ); | ||
131 | + }); | ||
132 | + }); | ||
133 | + }); | ||
134 | + }); | ||
135 | + | ||
136 | + queue.failed( function( err, ids ) { | ||
137 | + ids.forEach( function( id ) { | ||
138 | + kue.Job.get( id, function( err, job ) { | ||
139 | + job.remove( function(){ | ||
140 | + // console.log( 'removed ', job.id ); | ||
141 | + }); | ||
142 | + }); | ||
143 | + }); | ||
144 | + }); | ||
145 | + | ||
146 | + res.send(200, "Fila limpa"); | ||
147 | +}); | ||
148 | + | ||
93 | app.listen(properties.port, properties.host, function(){ | 149 | app.listen(properties.port, properties.host, function(){ |
94 | console.log('Server running on ' + properties.host + ':' + properties.port); | 150 | console.log('Server running on ' + properties.host + ':' + properties.port); |
95 | }); | 151 | }); |