Skip to content

Commit

Permalink
Update api.js
Browse files Browse the repository at this point in the history
  • Loading branch information
star7th committed Mar 21, 2019
1 parent 1707a94 commit 6a29f88
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions api.js
Expand Up @@ -146,7 +146,7 @@ app.post('/api/addTask', multipartMiddleware ,function (req, res){
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Credentials", "true");

var queue_name = config.redis_key_prefix+req.body.queue_name;
var queue_name = req.body.queue_name ? config.redis_key_prefix+req.body.queue_name : config.redis_key_prefix+"default_queue";
var url = req.body.url;
var post_app_key = req.body.app_key;
var post_app_token = req.body.app_token;
Expand All @@ -158,28 +158,32 @@ app.post('/api/addTask', multipartMiddleware ,function (req, res){
//判断是否在哈希表里存在队列名
redis_client.hexists(config.redis_key_prefix+"queue_list",queue_name,function(err, reply){
if (!reply) {
res.send('{"error_code":1003,"message":"队列不存在,请先创建"}');
}else{
if (execute_time) {
var score = Date.parse(new Date(execute_time));
//res.send('{"error_code":1003,"message":"队列不存在,请先创建"}');
//若不存在,则默认创建
var attribute = {"type":"real_time"};
redis_client.hmset(config.redis_key_prefix+"queue_list",queue_name,JSON.stringify(attribute));
}

if (execute_time) {
var score = Date.parse(new Date(execute_time));
}else{
var score = Date.parse(new Date());
}

if (url.indexOf("?") > -1 ) {
url += "&htq_no_repeat="+score+Math.random().toFixed(4);
}else{
url += "?htq_no_repeat="+score+Math.random().toFixed(4);
}
redis_client.zadd(queue_name,score,url,function(err, reply){
if (reply) {
res.send( '{"error_code":0,"message":"添加成功"}');
}else{
var score = Date.parse(new Date());
res.send('{"error_code":1001,"message":"添加失败"}');
}

if (url.indexOf("?") > -1 ) {
url += "&htq_no_repeat="+score+Math.random().toFixed(4);
}else{
url += "?htq_no_repeat="+score+Math.random().toFixed(4);
}
redis_client.zadd(queue_name,score,url,function(err, reply){
if (reply) {
res.send( '{"error_code":0,"message":"添加成功"}');
}else{
res.send('{"error_code":1001,"message":"添加失败"}');
}

});
}

});

});


Expand Down

0 comments on commit 6a29f88

Please sign in to comment.