Home > Enterprise >  How do I resolve Heroku Redis error using Flask App
How do I resolve Heroku Redis error using Flask App

Time:01-04

I have used information from link to add activate Redis queue in my Flask app: Heroku Redis

Following is the code in my app file.

from worker import conn
q = Queue(connection=conn)

@app.route('/pureredis', methods=['POST', 'GET'])
def pureredis():
  import createtable
  file = q.enqueue(createtable.test_task(),'http://heroku.com')
  return file

What I want here is to simply call test_task() from createtable.py file and show results in /pureredis

Meanwhile I have added a worker.py file to instantiate a conn.

Error I am getting is as follows:

2023-01-03T01:50:23.899221 00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/rq/utils.py", line 147, in import_attribute
raise ValueError('Invalid attribute name:   %s' % name)
ValueError: Invalid attribute name: {

I checked out some earlier tickets and tried but that did not help. stockoverflow redis

Information in link below is good but does not work for Heroku: flask with redis

CodePudding user response:

You are calling the function inside the enqueue function remember this expects a Callable

from this

job = q.enqueue(createtable.test_task(),'http://heroku.com')

to this

job = q.enqueue(createtable.test_task,'http://heroku.com')

Remember to return a valid response in your view.

  • Related