from rq import Queue from redis import Redis redis_conn = Redis(host='localhost', port=6379, db=0) q = Queue(connection=redis_conn) def my_task(): print('Executing my task...') job = q.enqueue(my_task)
from rq import Worker, Queue, Connection redis_conn = Redis(host='localhost', port=6379, db=0) q = Queue(connection=redis_conn) with Connection(redis_conn): worker = Worker(q) worker.work()In this example, we create a new RQ worker object and start it, which listens for jobs on the specified Redis queue. The worker will keep running until there are no more pending jobs left in the queue. Overall, RQ Worker is a powerful and flexible package library for managing background tasks and job queues in Python, making it easier to build and deploy robust and reliable applications that can handle complex asynchronous workflows.