gpt4 book ai didi

redis - Kue JSON API 不返回任何数据 - KUE with AWS Redis

转载 作者:可可西里 更新时间:2023-11-01 11:24:41 26 4
gpt4 key购买 nike

我正在使用 kue 对一些使用 node express 的 python 作业进行排队和处理。我使用的 redis 服务器不是 localhost 上的默认服务器,而是 AWS Redis。问题陈述:与 AWS redis 的连接成功,正在创建和处理作业,正在按预期从 python 作业生成输出文件,但是当使用的服务器是 AWS Redis 时,Kue JSON API 不会返回任何数据。如果它是本地主机上的 redis 服务器,API 会完美地返回数据。

1.这是我从节点到redis的连接代码

 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.作业队列和进程调用

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,所有工作详细信息都会按预期显示。

Kue UI Job details displayed as expected

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
}
});

如果我在本地主机上使用默认的 redis,此 API 调用将返回数据。

我可以做些什么来让 JSON API 从 AWS Redis 返回数据?如果我必须在本地主机上使用 redis-server 并且在连接到 AWS Redis 时 JSON API 的这种行为仍然存在,我就无法转移到 Prod。

感谢您的帮助。

最佳答案

您确定您的 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

关于redis - Kue JSON API 不返回任何数据 - KUE with AWS Redis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50006249/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com