This repository has been archived by the owner on Jun 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
51 lines (42 loc) · 1.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var redisModel = require('./redis_model')
, getJobs = require('./get_jobs')(redisModel)
module.exports = function (config) {
var router = config.router;
var redisClient = config.redisClient;
if (!router) throw new Error("Config must provide an express Router at key 'router'");
if (!redisClient) throw new Error("Config must provide a redis client at key 'redisClient'");
redisModel.setClient(redisClient)
var states = [ 'active', 'wait', 'failed', 'complete' ]
states.forEach(function(state) {
router.route('/'+state)
.get(function (req, res, next) {
getJobs(state).then(function(data){
res.json(data);
}).error(next).catch(next)
})
})
router.route('/pending/id/:type/:id')
.get(function (req, res, next) {
var id = req.params.id
, type = req.params.type
redisModel.makePendingById(type, id).then(function(results){
res.json(results);
}).error(next).catch(next)
});
router.route('/delete/id/:type/:id')
.get(function (req, res, next) {
var id = req.params.id
, type = req.params.type
redisModel.deleteJobById(type, id).then(function(results){
res.json(results);
}).error(next).catch(next)
});
router.route('/delete/status/:type')
.get(function (req, res, next) {
var type = req.params.type
redisModel.deleteJobByStatus(type).then(function(results){
res.json(results);
}).error(next).catch(next)
});
return router;
}