job仅在redis cli中可见,但不在rq Jmeter 板中显示,也不执行

xpcnnkqh  于 2021-06-09  发布在  Redis
关注(0)|答案(0)|浏览(308)

我想用redis和rq构建一个管道。我创建了一个worker、服务器和一个job,worker正在运行并侦听队列,服务器正在将一个job分派到一个队列,该job被分派并打印job id,在控制台中,我可以看到worker在队列中记录接收一个job的日志。作业从未执行,也从未在rq Jmeter 板中显示,但我可以在redis cli中看到它。
我使用的版本:
rq==1.7.0
redis==3.5.0
这是我的密码:
run.py中的worker

import os

import redis
from rq import Worker, Queue, Connection

listen = ['stance_queue','default']

redis_url = os.getenv('REDIS_URL', 'redis://redis:6379')

conn = redis.from_url(redis_url)

# conn = redis.Redis(host='redis', port=6379)

if __name__ == '__main__':
    with Connection(conn):
        print("Createing worker")
        worker = Worker(map(Queue, listen))
        # worker = Worker([Queue()])
        worker.work()

我给你派了份工作

from workers.stance.run import conn

q = Queue('default', connection=conn)

@server.route("/task")
def home():

    if request.args.get("n"):
        print('create a job in default queue')
        job = q.enqueue( background_task,  args=(20,))
        return f"Task ({job.id}) added to queue at {job.enqueued_at}"

    return "No value for count provided"

这是背景工作

def background_task(n):

    """ Function that returns len(n) and simulates a delay """

    delay = 2

    print("Task running", flush=True)
    print(f"Simulating a {delay} second delay", flush=True)

    time.sleep(delay)

    print(len(n))
    print("Task complete")

    return len(n)

这是rq Jmeter 板的截图

这是工人的日志

Attaching to annotators_server_stance_worker_1
stance_worker_1      | Createing worker
stance_worker_1      | 08:33:44 Worker rq:worker:cae161cf792b4c998376cde2c0848291: started, version 1.7.0
stance_worker_1      | 08:33:44 Subscribing to channel rq:pubsub:cae161cf792b4c998376cde2c0848291
stance_worker_1      | 08:33:44***Listening on stance_queue, default...
stance_worker_1      | 08:33:44 Cleaning registries for queue: stance_queue
stance_worker_1      | 08:33:44 Cleaning registries for queue: default
stance_worker_1      | 08:33:49 default: home.annotator_server.background_task(20) (9f1f31e0-f465-4019-9dc6-85bc349feab9)

这是redis cli的日志

mpose exec redis redis-cli

127.0.0.1:6379> keys *
1) "rq:workers"
2) "rq:failed:default"
3) "rq:clean_registries:default"
4) "rq:queues"
5) "rq:job:9f1f31e0-f465-4019-9dc6-85bc349feab9"
6) "rq:worker:cae161cf792b4c998376cde2c0848291"
7) "rq:workers:default"
8) "rq:clean_registries:stance_queue"
9) "rq:workers:stance_queue"

这是我的作品

version: '3'
services:
  annotators_server:
    build:  
      context: .
      dockerfile: Dockerfile
    ports:
     - "5000:5000"
    volumes:
     - ./app:/home
    depends_on:
    - redis     
  redis:
    image: "redis:alpine"
  dashboard:
    image: "godber/rq-dashboard"
    ports:
      - 9181:9181
    command: rq-dashboard -H redis
    depends_on:
      - redis      
  stance_worker:
    build:  
      context: ./app/workers/stance
      dockerfile: Dockerfile
    environment: 
      - REDIS_URL=redis://redis:6379
    depends_on:
    - redis

我从来没有看到作业执行的日志,我尝试添加ttl和timeout,但仍然面临相同的问题。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题