Skip to content

Commit

Permalink
Merge pull request #23 from vasumahesh1/master
Browse files Browse the repository at this point in the history
Added - queue level job management
  • Loading branch information
ShaneK committed Apr 8, 2016
2 parents 00fb50a + e5dd3e7 commit 185753d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
3 changes: 2 additions & 1 deletion controllers/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module.exports = function (app) {

app.get('/api/jobs/delete/status/:type', function (req, res) {
var type = req.param("type");
redisModel.deleteJobByStatus(type).done(function(results){
var queueName = req.param("queueName") ? req.param("queueName") : null;
redisModel.deleteJobByStatus(type, queueName).done(function(results){
res.json(results);
});
});
Expand Down
31 changes: 19 additions & 12 deletions models/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,37 @@ var _ = require("lodash"),
Promise = require('bluebird'),
q = require('q');

var getActiveKeys = function(){
var getActiveKeys = function(queueName){
var dfd = q.defer();
redis.keys("bull:*:active", function(err, keys){
queueName = queueName ? queueName : '*';
redis.keys("bull:" + queueName + ":active", function(err, keys){
dfd.resolve(keys);
});
return dfd.promise;
};

var getCompletedKeys = function(){
var getCompletedKeys = function(queueName){
var dfd = q.defer();
redis.keys("bull:*:completed", function(err, keys){
queueName = queueName ? queueName : '*';
redis.keys("bull:" + queueName + ":completed", function(err, keys){
dfd.resolve(keys);
});
return dfd.promise;
};

var getFailedKeys = function(){
var getFailedKeys = function(queueName){
var dfd = q.defer();
redis.keys("bull:*:failed", function(err, keys){
queueName = queueName ? queueName : '*';
redis.keys("bull:" + queueName + ":failed", function(err, keys){
dfd.resolve(keys);
});
return dfd.promise;
};

var getWaitingKeys = function(){
var getWaitingKeys = function(queueName){
var dfd = q.defer();
redis.keys("bull:*:wait", function(err, keys){
queueName = queueName ? queueName : '*';
redis.keys("bull:" + queueName + ":wait", function(err, keys){
dfd.resolve(keys);
});
return dfd.promise;
Expand All @@ -55,7 +59,7 @@ var getStuckKeys = function(){
return dfd.promise;
};

var getStatus = function(status){
var getStatus = function(status, queueName){
var dfd = q.defer();
var getStatusKeysFunction = null;
if(status === "complete"){
Expand All @@ -73,7 +77,7 @@ var getStatus = function(status){
return;
}

getStatusKeysFunction().done(function(keys){
getStatusKeysFunction(queueName).done(function(keys){
var multi = [];
var statusKeys = [];
for(var i = 0, ii = keys.length; i < ii; i++){
Expand Down Expand Up @@ -286,15 +290,15 @@ var makePendingById = function(type, id){
return dfd.promise;
};

var deleteJobByStatus = function(type){
var deleteJobByStatus = function(type, queueName){
type = type.toLowerCase();
var validTypes = ['active', 'complete', 'failed', 'wait']; //I could add stuck, but I won't support mass modifying "stuck" jobs because it's very possible for things to be in a "stuck" state temporarily, while transitioning between states
var dfd = q.defer();
if(validTypes.indexOf(type) === -1) {
dfd.resolve({success:false, message:"Invalid type: "+type+" not in list of supported types"});
return dfd.promise;
}
getStatus(type).done(function(allKeys){
getStatus(type, queueName).done(function(allKeys){
var multi = [];
var allKeyObjects = Object.keys(allKeys.keys);
for(var i = 0, ii = allKeyObjects.length; i < ii; i++){
Expand All @@ -313,6 +317,9 @@ var deleteJobByStatus = function(type){
if(err){
dfd.resolve({success: false, message: err});
}else{
if (queueName) {
dfd.resolve({success: true, message: "Successfully deleted all jobs of status " + type +" of queue " + queueName + "."});
}
dfd.resolve({success: true, message: "Successfully deleted all jobs of status " + type +"."});
}
});
Expand Down
11 changes: 9 additions & 2 deletions public/js/RedisHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ var RedisHandler = function(){
});
});
},
deleteByStatus: function(status){
deleteByStatus: function(status, obj){
var queueName = obj.name;
status = status.toLowerCase();
var statusDisplay = status;
if(status === "pending"){
Expand All @@ -40,7 +41,13 @@ var RedisHandler = function(){
}
_self.util.notyConfirm("Are you sure you want to delete <strong>all</strong> jobs with the status "+statusDisplay+"?", function(){
_self.util.blockUI();
$.getJSON(window.basepath + "/api/jobs/delete/status/"+status).done(function(response){
var targetUrl = null;
if (queueName) {
targetUrl = window.basepath + "/api/jobs/delete/status/"+status + "?queueName=" + queueName;
} else {
targetUrl = window.basepath + "/api/jobs/delete/status/"+status;
}
$.getJSON(targetUrl).done(function(response){
if(status !== statusDisplay && response.success){
response.message = response.message.replace(status, statusDisplay);
}
Expand Down
15 changes: 15 additions & 0 deletions public/templates/queueList.dust
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Matador
<th>Active</th>
<th>Completed</th>
<th>Failed</th>
<th>Options</th>
</tr>
</thead>
<tbody data-bind="foreach: keys">
Expand All @@ -30,6 +31,20 @@ Matador
<td data-bind="text: active"></td>
<td data-bind="text: completed"></td>
<td data-bind="text: failed"></td>
<td>
<div class="dropdown">
<button data-toggle="dropdown" data-bind="attr: { id: 'queue_dropdown_' + $index() }" class="btn btn-default dropdown-toggle">
<i class="fa fa-cog"></i>
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" data-bind="attr: { "aria-labelledby": 'queue_dropdown_' + $index() }">
<li><a href="#" data-bind="click: function(data, event) { redisHandler.fn.deleteByStatus('wait', data) }">Delete All Pending</a></li>
<li><a href="#" data-bind="click: function(data, event) { redisHandler.fn.deleteByStatus('active', data) }">Delete All Active</a></li>
<li><a href="#" data-bind="click: function(data, event) { redisHandler.fn.deleteByStatus('complete', data) }">Delete All Completed</a></li>
<li><a href="#" data-bind="click: function(data, event) { redisHandler.fn.deleteByStatus('failed', data) }">Delete All Failed</a></li>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
Expand Down

0 comments on commit 185753d

Please sign in to comment.