user1960118
user1960118

Reputation: 369

RQ Scheduler throws NoRedisConnectionException

I am building an application and I am attempting to setup scheduled tasks with Redis/python-rq/rq-scheduler.

I can setup a Queue just fine, like so:

from redis import Redis
from rq import Queue

rq = Queue(connection=Redis(host=BaseConfig.REDIS_HOST, port=BaseConfig.REDIS_PORT))

def hello_world():
    print("hello world")

@app.route("/queue/test", method=["GET", "POST"])
def test_queue():
    job = rq.enqueue_call(func=hello_world)
    return jsonify(job_id=job.id())

But now when I try to setup a scheduled task, according to the documentation here link. Like so:

from datetime import timedelta

from redis import Redis
from rq import Queue
from rq_scheduler import Scheduler

rq = Queue(connection=Redis(host=BaseConfig.REDIS_HOST, port=BaseConfig.REDIS_PORT))
rqs = Scheduler(queue=rq)

def hello_world():
    print("hello world")

@app.route("/queue/test", method=["GET", "POST"])
def test_queue():
    job = rqs.enqueue_in(timedelta(seconds=30), func=hello_world)
    return jsonify(job_id=job.id())

I get

raise NoRedisConnectionException('Could not resolve a Redis connection')                                                                                                                                                                   
rq.connections.NoRedisConnectionException: Could not resolve a Redis connection

All help would be appreciated. Thank you.

Upvotes: 1

Views: 799

Answers (1)

Arun Aggarwal
Arun Aggarwal

Reputation: 11

You need to pass connection while creating scheduler object

Upvotes: 1

Related Questions