> A "tasks fired by tasks" is a perfect example: what if you want to queue 
> your tasks only if the "parent" completed correctly ?


This makes perfect sense.  Also I forget that the "message passing" is 
being done through the database.  I added a db.commit() at the end of the 
parent task and all is right with the world.

You're saving my life today! Thanks,

Dean

 
On Wednesday, April 24, 2013 5:14:46 PM UTC-4, Niphlod wrote:
>
> you're probably missing the part where a task gets executed in a 
> "shell-like" environment, whose most-notable difference is that you have to 
> manually db.commit().
>
> While a db.commit() is ensured "automatically" at the end of every request 
> in the normal web environment by web2py, inside a task you may want to 
> commit() or rollback() "as per requirements".
>
> That's the reason why queue_task() doesn't enforce a db.commit() .... in a 
> normal environment your task queued by the "web" is committed only if there 
> aren't exceptions. Perfect! (you don't want to queue tasks if the 
> controller function that generated it threw an exception)
>  
> A "tasks fired by tasks" is a perfect example: what if you want to queue 
> your tasks only if the "parent" completed correctly ?
>
> e.g.
>
> def parent_task():
>     ... do_something
>     ... queue_task(child_task, ...)
>     1/0
>     ...whoopsie!
>
> def child_task():
>     """I must run only if parent_task() completed correctly"""
>     ... do_something()
>
> so, just db.commit() at the end of parent_task and you're good to go.
>
> PS: restating over and over (in case it's not clear). Whatever you do in 
> your tasks involving a database must be commit()ed. This involves queueing 
> new tasks cause you're using the database to queue them.
>
>
On Wednesday, April 24, 2013 5:14:46 PM UTC-4, Niphlod wrote:
>
> you're probably missing the part where a task gets executed in a 
> "shell-like" environment, whose most-notable difference is that you have to 
> manually db.commit().
>
> While a db.commit() is ensured "automatically" at the end of every request 
> in the normal web environment by web2py, inside a task you may want to 
> commit() or rollback() "as per requirements".
>
> That's the reason why queue_task() doesn't enforce a db.commit() .... in a 
> normal environment your task queued by the "web" is committed only if there 
> aren't exceptions. Perfect! (you don't want to queue tasks if the 
> controller function that generated it threw an exception)
>  
> A "tasks fired by tasks" is a perfect example: what if you want to queue 
> your tasks only if the "parent" completed correctly ?
>
> e.g.
>
> def parent_task():
>     ... do_something
>     ... queue_task(child_task, ...)
>     1/0
>     ...whoopsie!
>
> def child_task():
>     """I must run only if parent_task() completed correctly"""
>     ... do_something()
>
> so, just db.commit() at the end of parent_task and you're good to go.
>
> PS: restating over and over (in case it's not clear). Whatever you do in 
> your tasks involving a database must be commit()ed. This involves queueing 
> new tasks cause you're using the database to queue them.
>
>
On Wednesday, April 24, 2013 5:14:46 PM UTC-4, Niphlod wrote:
>
> you're probably missing the part where a task gets executed in a 
> "shell-like" environment, whose most-notable difference is that you have to 
> manually db.commit().
>
> While a db.commit() is ensured "automatically" at the end of every request 
> in the normal web environment by web2py, inside a task you may want to 
> commit() or rollback() "as per requirements".
>
> That's the reason why queue_task() doesn't enforce a db.commit() .... in a 
> normal environment your task queued by the "web" is committed only if there 
> aren't exceptions. Perfect! (you don't want to queue tasks if the 
> controller function that generated it threw an exception)
>  
> A "tasks fired by tasks" is a perfect example: what if you want to queue 
> your tasks only if the "parent" completed correctly ?
>
> e.g.
>
> def parent_task():
>     ... do_something
>     ... queue_task(child_task, ...)
>     1/0
>     ...whoopsie!
>
> def child_task():
>     """I must run only if parent_task() completed correctly"""
>     ... do_something()
>
> so, just db.commit() at the end of parent_task and you're good to go.
>
> PS: restating over and over (in case it's not clear). Whatever you do in 
> your tasks involving a database must be commit()ed. This involves queueing 
> new tasks cause you're using the database to queue them.
>
>

-- 

--- 
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/groups/opt_out.


Reply via email to