On Wednesday, June 17, 2020 at 6:41:32 AM UTC-7, Pierre wrote:
>
> Gooday,
> In the controler the function works correctly. But as a task, it gives an
> error about Json not beeing able to deal with datetime.
> any suggestion would be appreciated :)
>
> here is the error : TypeError: datetime.datetime(2020, 6, 16, 5, 17, 49)
> is not JSON serializable
>
>
This does not look right:
> from gluon.scheduler import Scheduler
>
> Scheduler(db,dict(sync_data=pump_most_recent,sync_dates=acue_src_dst_update))
>
>
In a models file called scheduler.py, I have:
from gluon.scheduler import Scheduler
scheduler = Scheduler(db)
def taskfunc(arg1, arg2):
var1 = do_something(arg1)
if var1 in arg2:
return "success"
In a controller, I kick off the task with
chunk1 = dostuff(request.args[0])
string1 = targets[rand()]
tid = scheduler.queue_task('taskfunc', pvars={'arg1': chunk1, 'arg2':
string2}, timeout=1200)
(the controller knows scheduler from the models)
Sending a date as an argument would be done by using a pvars dictionary in
the same way. For one of my tasks, I send a datetime via pvars. The
task also has a request.now. (It has the whole request, but you can tell
it's a scheduler request).
Do you find the documentation on Scheduler unclear?
/dps
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/38b335a6-4ea8-4977-9095-c321447fb462o%40googlegroups.com.