Thanks for the help, the solution is perfect for me.

Le samedi 27 décembre 2014 18:16:16 UTC+1, Niphlod a écrit :
>
> uhm....... there's not a stable API to do it, but you can access the 
> relative scheduler_task record via W2P_TASK. 
> From web2py 2.4.1, any task processed by the scheduler can access a global 
> variable named W2P_TASK that is a Storage() holding the id and the uuid of 
> the running task.
>
> this means you can do, within the queued task, something like
>
> def mytask():
>     print W2P_TASK.id, W2P_TASK.uuid
>
> Back to your problem: to know if it's the first iteration you have two 
> methods: checking how many "results" the task has (assuming you're 
> returning something at the end of "mytask" and you didn't istantiate the 
> Scheduler with discard_results=True) or checking the actual times a task 
> has been executed.
> Assuming "dbsched" is the DAL istance used by the scheduler, the first 
> info can be retrieved by 
>
> howmany = dbsched(dbsched.scheduler_run.task_id == W2P_TASK.id).count()
>
> the second info instead is on the scheduler_task table directly:
>
> thetask = dbsched.scheduler_task(W2P_TASK.id)
> howmany = thetask.times_run 
>
> I'd go with the former method if I had a gun pointed to my head.
>
> However, because I don't like guns, I'd tackle the problem from an 
> entirely different perspective: I'd queue a one-time-only task for 
> "treatment A" that at the end queues a repeating task for "treatment B". 
> It would be simpler, with more separation between the components, easier 
> to debug and would work even if you use some other task processors.. also, 
> you'll be protecting your app if in the future the schema of the scheduler 
> tables changes in the future (unlikely but entirely possible).
>
>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to