skip to Main Content

I’m pretty new to Redis queuing job task. I tried to do some function on the queue by using Redis To Go Add-on. But after I push some task on queue it seems to disappear.

Here is my code

import Flask
import redis
from rq import Queue

REDIS_URL = os.getenv('REDISTOGO_URL', None)
if REDIS_URL!=None:
    r = redis.from_url(REDIS_URL)
else:
    r = redis.Redis()

q = Queue(connection=r)

def function(pam1):
    print("Checkpoint1")
    return 0

@main.route('/name', methods=['GET', 'POST'])
def displayname():
    job = q.enqueue(function, pam1=0)
    return job.id

Additional info on queue: There still give the job id eg.7344337b-cca0-442a-b43a-abcdc88f012c.

but no sign of “Checkpoint1” on heroku log at all.

2

Answers


  1. Chosen as BEST ANSWER

    Thanks to @v25. The real reason that Redis not responds because I don't have a WORKER. After get thu see the Heroku guide on launching a worker now my problem solved.


  2. I’m not sure about Heroku’s logging implementation, but assuming you’re looking at the wrong log (or something) you could try this…

    Instead of printing ‘Checkpoint’, increment the value of a custom redis key:

    def function(pam1):
        r.incr('job_ran', 1)
        return 0
    

    Then create a route where you can check this value:

    @app.route('/show_count')
    def show_count():
        n = r.get('job_ran')
    
        if n is None:
            n = 0
        else:
            n = n.decode('utf-8')
    
        return f'Job has run {n} times'
    

    Now enqueue a few jobs, and check the /show_count route to make sure it has incremented accordingly.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search