我正在使用kue使用node express来排队和处理一些python作业。我使用的redis服务器不是localhost上的默认服务器,而是AWS Redis。 问题陈述:与AWS redis的连接成功,正在创建和处理作业,正在按照预期从python作业生成输出文件,但是当使用的服务器是AWS Redis时,Kue JSON API不返回任何数据。如果它是localhost上的redis-server,那么API会很好地返回数据。
1.这是我的连接代码,来自节点
const redisclient = redis.createClient({host: hostname, port: 6379});
var kue = require('kue'), queue = kue.createQueue({
prefix: 'q',
redis: {
port: 6379,
host: hostname,
options: {
disableSearch: false,
client: redisclient
}
}
});//redis connection works AWS
2.为Express快速安装Kue UI
var kueUiExpress = require('kue-ui-express');
kueUiExpress(app, '/kue/', '/kue-api/');
app.use('/kue-api/', kue.app);
3.Job队列和进程调用
var suspendusershdl = queue.create('suspendusershdl', {username: currentuseremail, title: "Generate HDL file to Suspend Users", inputfile: inputfilepathname, inputcoll: collname, outputfile: outputfilepathname , pythonscript: 'suspendusershdl.py' });
suspendusershdl.searchKeys( ['username'], 'username' ).save(); //indexing by username
suspendusershdl.on('complete', function(result){
console.log('Job is now complete');
console.log('Job Details:', suspendusershdl);
//Additional logic when job is complete
});
queue.process('suspendusershdl', function(suspendusershdl, done){
//process the job, processing logic here
});
4.这就是我在这一点上所看到的。如果我去Kue UI,所有工作细节都会按预期显示。
5.这就是我在关于AWS Redis实例的redis-cli上的MONITOR上看到的内容。
1524582499.883115 [0 172.31.31.246:53372] "incr" "q:ids"
1524582499.887225 [0 172.31.31.246:53372] "hset" "q:job:3" "max_attempts" "1"
1524582499.887273 [0 172.31.31.246:53372] "sadd" "q:job:types" "suspendusershdl"
1524582499.887448 [0 172.31.31.246:53372] "hset" "q:job:3" "type" "suspendusershdl"
1524582499.887462 [0 172.31.31.246:53372] "hset" "q:job:3" "created_at" "1524582499888"
1524582499.887470 [0 172.31.31.246:53372] "hset" "q:job:3" "promote_at" "1524582499888"
1524582499.887679 [0 172.31.31.246:53372] "hset" "q:job:3" "updated_at" "1524582499888"
1524582499.887951 [0 172.31.31.246:53372] "hset" "q:job:3" "priority" "0"
1524582499.888013 [0 172.31.31.246:53372] "zadd" "q:jobs" "0" "01|3"
1524582499.888069 [0 172.31.31.246:53372] "hset" "q:job:3" "data" "{\"username\":\"abc@company.com\",\"title\":\"Generate HDL file to Suspend Users\",\"inputfile\":\"inputfilepathname",\"inputcoll\":\"suspendusers1524582499883\",\"outputfile\":\"outputfilepathname\",\"pythonscript\":\"suspendusershdl.py\"}"
1524582499.889688 [0 172.31.31.246:53372] "hset" "q:job:3" "updated_at" "1524582499890"
1524582499.889806 [0 172.31.31.246:53372] "multi"
1524582499.889816 [0 172.31.31.246:53372] "hset" "q:job:3" "state" "inactive"
1524582499.889822 [0 172.31.31.246:53372] "zadd" "q:jobs:inactive" "0" "01|3"
1524582499.889829 [0 172.31.31.246:53372] "zadd" "q:jobs:suspendusershdl:inactive" "0" "01|3"
1524582499.889836 [0 172.31.31.246:53372] "lpush" "q:suspendusershdl:jobs" "1"
1524582499.889844 [0 172.31.31.246:53372] "exec"
1524582499.941285 [0 172.31.31.246:53398] "info"
1524582499.941381 [0 172.31.31.246:53400] "info"
1524582499.941507 [0 172.31.31.246:53402] "info"
1524582499.943331 [0 172.31.31.246:53398] "select" "0"
1524582499.943340 [0 172.31.31.246:53398] "blpop" "q:suspendusershdl:jobs" "0"
1524582499.943541 [0 172.31.31.246:53400] "select" "0"
1524582499.943780 [0 172.31.31.246:53402] "select" "0"
1524582499.944132 [0 172.31.31.246:53402] "publish" "q:events" "{\"id\":3,\"event\":\"enqueue\",\"args\":[\"enqueue\",\"suspendusershdl\"]}"
1524582499.945201 [0 172.31.31.246:53372] "multi"
1524582499.945211 [0 172.31.31.246:53372] "zrange" "q:jobs:suspendusershdl:inactive" "0" "0"
1524582499.945220 [0 172.31.31.246:53372] "zremrangebyrank" "q:jobs:suspendusershdl:inactive" "0" "0"
1524582499.945229 [0 172.31.31.246:53372] "exec"
1524582499.947129 [0 172.31.31.246:53402] "hgetall" "q:job:3"
1524582499.949203 [0 172.31.31.246:53372] "hset" "q:job:3" "started_at" "1524582499949"
1524582499.949298 [0 172.31.31.246:53372] "hset" "q:job:3" "workerId" "kue:ip-172-31-31-246:10624:suspendusershdl:1"
1524582499.949467 [0 172.31.31.246:53372] "hset" "q:job:3" "updated_at" "1524582499950"
1524582499.949550 [0 172.31.31.246:53372] "multi"
1524582499.949563 [0 172.31.31.246:53372] "zrem" "q:jobs:inactive" "01|3"
1524582499.949570 [0 172.31.31.246:53372] "zrem" "q:jobs:suspendusershdl:inactive" "01|3"
1524582499.949575 [0 172.31.31.246:53372] "hset" "q:job:3" "state" "active"
1524582499.949580 [0 172.31.31.246:53372] "zadd" "q:jobs:active" "0" "01|3"
1524582499.949596 [0 172.31.31.246:53372] "zadd" "q:jobs:suspendusershdl:active" "0" "01|3"
1524582499.949603 [0 172.31.31.246:53372] "zadd" "q:jobs:active" "0" "01|3"
1524582499.949608 [0 172.31.31.246:53372] "exec"
1524582499.951338 [0 172.31.31.246:53402] "publish" "q:events" "{\"id\":3,\"event\":\"start\",\"args\":[\"start\",\"suspendusershdl\",null]}"
1524582500.005064 [0 172.31.31.246:53372] "rpush" "q:job:3:log" "File Imported Successfully to MongoDB"
1524582500.005121 [0 172.31.31.246:53372] "hset" "q:job:3" "updated_at" "1524582500005"
1524582500.005188 [0 172.31.31.246:53372] "rpush" "q:job:3:log" "Calling Exec Python"
1524582500.005225 [0 172.31.31.246:53372] "hset" "q:job:3" "updated_at" "1524582500005"
1524582500.138182 [0 172.31.31.246:53390] "multi"
1524582500.138202 [0 172.31.31.246:53390] "zinterstore" "q:searchtmpkey" "3" "q:search:word:HLTMN" "q:search:word:RSP" "q:search:word:KM"
1524582500.138219 [0 172.31.31.246:53390] "zrevrange" "q:searchtmpkey" "0" "-1"
1524582500.138224 [0 172.31.31.246:53390] "zremrangebyrank" "q:searchtmpkey" "0" "-1"
1524582500.138230 [0 172.31.31.246:53390] "exec"
1524582500.620289 [0 172.31.31.246:53372] "rpush" "q:job:3:log" "suspendusershdl.py completed successfully."
1524582500.620317 [0 172.31.31.246:53372] "hset" "q:job:3" "updated_at" "1524582500620"
1524582500.620497 [0 172.31.31.246:53372] "hset" "q:job:3" "duration" "672"
1524582500.620592 [0 172.31.31.246:53372] "hset" "q:job:3" "progress" "100"
1524582500.620684 [0 172.31.31.246:53372] "hset" "q:job:3" "updated_at" "1524582500621"
1524582500.620779 [0 172.31.31.246:53372] "multi"
1524582500.620792 [0 172.31.31.246:53372] "zrem" "q:jobs:active" "01|3"
1524582500.620799 [0 172.31.31.246:53372] "zrem" "q:jobs:suspendusershdl:active" "01|3"
1524582500.620806 [0 172.31.31.246:53372] "hset" "q:job:3" "state" "complete"
1524582500.620811 [0 172.31.31.246:53372] "zadd" "q:jobs:complete" "0" "01|3"
1524582500.620821 [0 172.31.31.246:53372] "zadd" "q:jobs:suspendusershdl:complete" "0" "01|3"
1524582500.620828 [0 172.31.31.246:53372] "exec"
1524582500.622509 [0 172.31.31.246:53372] "hincrby" "q:job:3" "attempts" "1"
1524582500.624102 [0 172.31.31.246:53402] "publish" "q:events" "{\"id\":3,\"event\":\"complete\",\"args\":[\"complete\",null,null]}"
1524582500.624224 [0 172.31.31.246:53372] "incrby" "q:stats:work-time" "672"
1524582500.624382 [0 172.31.31.246:53398] "blpop" "q:suspendusershdl:jobs" "0"
1524582500.887372 [0 172.31.31.246:53400] "set" "promotion:lock" "U3dicEfREeiGI0kMM36BPg==" "PX" "2000" "NX"
1524582500.887552 [0 172.31.31.246:53400] "set" "activeJobsTTL:lock" "U3eJgEfREeiGI0kMM36BPg==" "PX" "2000" "NX"
1524582500.889253 [0 172.31.31.246:53372] "zrangebyscore" "q:jobs:delayed" "0" "1524582500889" "LIMIT" "0" "1000"
1524582500.889452 [0 172.31.31.246:53372] "zrangebyscore" "q:jobs:active" "100000" "1524582500890" "LIMIT" "0" "1000"
1524582500.892561 [0 172.31.31.246:53400] "script" "load" "--\n-- Delete a key if content is equal\n--\n-- KEYS[1] - key\n-- KEYS[2] - content\nlocal key = KEYS[1]\nlocal content = ARGV[1]\n\nlocal value = redis.call('get', key)\n\nif value == content then\n return redis.call('del', key);\nend\n\nreturn 0\n"
6.太好了。现在我调用JSON API来查询用户安排的所有作业。
request({'rejectUnauthorized': false, 'url': 'https://example.com/kue-api/job/search?q=' + currentuseremail, 'method': 'GET'}, function(error, response, body) {
if (error) {
console.log(error);
res.json({ success : false, message : 'Error', jobs: processesfromkue});
} else {
processesfromkue = JSON.parse(body);
console.log('Number of processes in kue for user: ', processesfromkue.length);
res.json({ success : true, message : 'Kue Jobs retrieved', jobs: processesfromkue}); //This API Call always results in success and the array of jobs returned is empty although there are jobs displayed in the DB and UI
}
});
如果我在localhost上使用默认的redis,则此API调用将返回数据。
有什么办法可以让JSON API从AWS Redis返回数据吗?如果我必须在localhost上使用redis-server,并且在连接到AWS Redis时JSON API的这种行为仍然存在,我无法转移到Prod。
感谢您的帮助。
答案 0 :(得分:0)
您确定Redis实例与Kue / Node服务器在同一VPC中吗?
测试与AWS Redis的连接的一种方法是登录服务器或同一VPC中的服务器。安装redis-cli并测试连接。
您可以使用以下命令安装redis-cli:
yum install libjemalloc1 libjemalloc-dev gcc make -y
cd /tmp
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
cp src/redis-cli /usr/local/bin/
chmod 755 /usr/local/bin/redis-cli
重新登录,然后:
测试连接:
redis-cli -c -h REDIS.URL.cache.amazonaws.com -p 6379