Reputation: 41
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
Upvotes: 1
Views: 219
Reputation: 341
Unrelated to OP's issue, but I had similar errors:
2023-08-31T11:58:37.037006+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/site-packages/rq/utils.py", line 109, in import_attribute
2023-08-31T11:58:37.037006+00:00 app[worker.1]: raise ValueError('Invalid attribute name: %s' % name)
2023-08-31T11:58:37.037007+00:00 app[worker.1]: ValueError: Invalid attribute name: mymodule.myfunction
Solution:
The module I imported was missing dependencies.
In my case the mymodule.myfunction
was utilizing requests
so I added requests
to requirements.txt
and problem was solved.
Upvotes: 0
Reputation: 158
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.
Upvotes: 1