What I do currently: create a scheduler in a dedicated model:
from gluon.scheduler import Scheduler
from jobs import testfunc
scheduler = Scheduler(db, dict(testfunc_task=testfunc))Then in a controller, I do:
task_kwargs = { 'immediate': True, 'task_name': 'ImportContacts-' + str(time.time())[:-4], }
from jobs import testfunc
scheduler.queue_task(testfunc, pargs=[request.vars.sna], kwargs=task_kwargs)
and I get an exception saying that table
socialjack.scheduler_task does not exist (traceback below). But the table IS there, I can see it in the db admin interface and on the MySQL console ... Please help! Thanks!
Traceback (most recent call last):
File "/home/www-data/web2py/gluon/restricted.py", line 217, in restricted
exec ccode in environment
File "/home/www-data/web2py-2.8.2/applications/socialjack/controllers/contacts.py", line 236, in <module>
File "/home/www-data/web2py/gluon/globals.py", line 372, in <lambda>
self._caller = lambda f: f()
File "/home/www-data/web2py/gluon/tools.py", line 3239, in f
return action(*a, **b)
File "/home/www-data/web2py-2.8.2/applications/socialjack/controllers/contacts.py", line 54, in importcontacts
scheduler.queue_task(testfunc, pargs=[request.vars.sna], kwargs=task_kwargs)
File "/home/www-data/web2py/gluon/scheduler.py", line 983, in queue_task
**kwargs)
File "/home/www-data/web2py/gluon/dal.py", line 9114, in validate_and_insert
value,error = self[key].validate(value)
File "/home/www-data/web2py/gluon/dal.py", line 10036, in validate
(value, error) = validator(value)
File "/home/www-data/web2py/gluon/validators.py", line 668, in __call__
row = subset.select(table._id, field, limitby=(0, 1), orderby_on_limitby=False).first()
File "/home/www-data/web2py/gluon/dal.py", line 10450, in select
return adapter.select(self.query,fields,attributes)
File "/home/www-data/web2py/gluon/dal.py", line 1861, in select
return self._select_aux(sql,fields,attributes)
File "/home/www-data/web2py/gluon/dal.py", line 1826, in _select_aux
self.execute(sql)
File "/home/www-data/web2py/gluon/dal.py", line 1948, in execute
return self.log_execute(*a, **b)
File "/home/www-data/web2py/gluon/dal.py", line 1942, in log_execute
ret = self.cursor.execute(command, *a[1:], **b)
File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
ProgrammingError: (1146, "Table 'socialjack.scheduler_task' doesn't exist")