Error background task with Redis

108 views
Skip to first unread message

Fabiano Faver

unread,
Jun 16, 2015, 1:03:42 PM6/16/15
to web...@googlegroups.com
I have tried to follow this tutorial: http://www.web2pyslices.com/slice/show/1579/web2py-and-redis-queue

Just changed the arguments in the enqueue function to be fixed:
def contato():
    form = SQLFORM.factory(Field("name"), Field("message"))
    if form.accepts(request):
        # enqueue the email to be sent!
       job =  q.enqueue(mail.send,
                  to="som...@teste.com.br",  # I CHANGED THE EMAIL HERE
                  subject="test contacted you",
                   message="message")
        # do whatever you want
       response.flash = "email successfully sent!"
    return dict(form=form)

But it gives me a error. After some time I figured out it was asking the function name to be a string.
Traceback (most recent call last):
File "/home/www-data/web2py/gluon/restricted.py", line 227, in restricted
exec ccode in environment
File "/home/www-data/web2py/applications/OPM/controllers/default.py", line 1772, in <module>
File "/home/www-data/web2py/gluon/globals.py", line 412, in <lambda>
self._caller = lambda f: f()
File "/home/www-data/web2py/applications/OPM/controllers/default.py", line 1750, in contato
message="message")
File "/usr/local/lib/python2.7/dist-packages/rq-0.5.3-py2.7.egg/rq/queue.py", line 253, in enqueue
job_id=job_id, at_front=at_front)
File "/usr/local/lib/python2.7/dist-packages/rq-0.5.3-py2.7.egg/rq/queue.py", line 215, in enqueue_call
return self.enqueue_job(job, at_front=at_front)
File "/usr/local/lib/python2.7/dist-packages/rq-0.5.3-py2.7.egg/rq/queue.py", line 270, in enqueue_job
job.save(pipeline=pipeline)
File "/usr/local/lib/python2.7/dist-packages/rq-0.5.3-py2.7.egg/rq/job.py", line 461, in save
connection.hmset(key, self.to_dict())
File "/usr/local/lib/python2.7/dist-packages/rq-0.5.3-py2.7.egg/rq/job.py", line 427, in to_dict
obj['data'] = self.data
File "/usr/local/lib/python2.7/dist-packages/rq-0.5.3-py2.7.egg/rq/job.py", line 227, in data
self._data = dumps(job_tuple)
File "/home/www-data/web2py/gluon/storage.py", line 56, in <lambda>
__getnewargs__ = lambda self: getattr(dict,self).__getnewargs__(self)
TypeError: getattr(): attribute name must be string

But if i do it I get another error, but this time on Redis side about it could not import modules.

 ImportError: No module named modules

Anyone had this problem? Couldn't figured out how to solve it.

Fabiano Faver

unread,
Jun 16, 2015, 1:15:03 PM6/16/15
to web...@googlegroups.com
Failed to copy the 2 error. The full traceback of the second error:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/rq-0.5.3-py2.7.egg/rq/worker.py", line 558, in perform_job
    rv = job.perform()
  File "/usr/local/lib/python2.7/dist-packages/rq-0.5.3-py2.7.egg/rq/job.py", line 495, in perform
    self._result = self.func(*self.args, **self.kwargs)
  File "/usr/local/lib/python2.7/dist-packages/rq-0.5.3-py2.7.egg/rq/job.py", line 206, in func
    return import_attribute(self.func_name)
  File "/usr/local/lib/python2.7/dist-packages/rq-0.5.3-py2.7.egg/rq/utils.py", line 150, in import_attribute
    module = importlib.import_module(module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/www-data/web2py/gluon/custom_import.py", line 85, in custom_importer
    modules_prefix, globals, locals, [itemname], level)
ImportError: No module named modules

Jose de Soto

unread,
Dec 21, 2016, 12:06:37 PM12/21/16
to web2py-users
Hi Fabiano,

Maybe to late. Here you have a full app based in python-rq:

黄祥

unread,
May 19, 2018, 9:27:27 PM5/19/18
to web2py-users
trying jose repo web2py-rq-dashboard, not sure how it's work
- start worker in web is different from execute in terminal using rqworker (from web there is high-1,normal-1,low-1 in the queue column and in rqworker queue = default)
- just run 1 rqworker in terminal but it shown 2 worker (from rqworker)
- click test random queue, it seems ended with failed
- start worker generate from web seems unstable, state change into pause and then gone (double check with rqinfo)

step i took:
- copy repo
cd ~/python/web2py/applications

- start redis server from source install (stable version 4.0.9)
./src/redis-server

- start web2py (stable version 2.16.1 on python 2.7)
source activate test2
python ~/python/web2py/web2py.py --nogui --no-banner -a a -i 0.0.0.0 -p 8000

- open via browser

- start rqworker in terminal
source activate test2
rqworker

- start rqinfo in terminal
source activate test2
rqinfo

perhaps i misunderstood about how this work, pls advice

thx and best regards,
stifan
Reply all
Reply to author
Forward
0 new messages