On Sunday, January 29, 2017 at 7:53:45 PM UTC-5, Filipe Reis wrote:
>
> Hey guys, I am trying to start a task from a task and I found this post: 
> https://groups.google.com/forum/?fromgroups#!searchin/web2py/queue$20tasks|sort:relevance/web2py/mpVWhW5QVxw/yufdedADDbYJ
>
> However I still have one issue where I get: AttributeError: type object 
> 'datetime.datetime' has no attribute 'datetime'
>
> For testing purposes I'm just doing:
>
> Controller:
> scheduler.queue_task(task_add, pvars=dict(a=1,b=2), repeats=1)
>
> Scheduler:
>
> def task_child(a,b):
>     return a+b
>
> def task_add(a,b):
>    scheduler.queue_task(task_child, pvars=dict(a=a, b=b), repeats=1)
>

As suggested in the post you linked above, you must call db.commit() for 
the task to be queued:

def task_add(a,b):
    scheduler.queue_task(task_child, pvars=dict(a=a, b=b), repeats=1)
    db.commit()

scheduler.queue_task simply inserts a record in the database, so you must 
do a commit after it is called. Note, the commit is not necessary when 
calling .queue_task() within the context of an HTTP request, because the 
framework automatically does a commit at the end of every HTTP request. In 
this case, though, .queue_task() is not being called during an HTTP 
request, but instead during the execution of another task (which is 
happening in a scheduler worker process).

Anthony

-- 
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].
For more options, visit https://groups.google.com/d/optout.

Reply via email to