James | 8 Apr 2010 13:34
Picon

Re: Race Conditions

Why not just do the calender and folder creation in 1 task? That way
your response time of your app is still fast and you don't have to
worry about race conditions.

-James

On Apr 7, 5:04 am, lfborjas <luis.bor...@...> wrote:
> Hello, world!
>
> I'm using celery for a django project to solve a very specific need:
> my project creates a folder in google docs and a calendar in google
> calendar whenever a user creates certain kinds of objects; because
> this is something the user doesn't actually start and can live without
> for a moment, I decided to let celery tasks take care of it (one task
> creates the calendar and the other, the folder).
>     I read what the docs say about race conditions (http://
> ask.github.com/celery/userguide/tasks.html#state) and hence I am using
> the object's id to re-fetch it from the database. As I can infer from
> the log, celery is running the folder task first and then the
> calendar, so far, so good, they both end with success and the calendar
> and folder are visible in the corresponding google sites.
>    BUT, I am also associating the folder and calendar ids to the
> object, so I expected, upon seeing both created without much ado, to
> go to the database and see both fields full, but, alas! Only the
> calendar field was updated! Reading the log, I saw that the calendar
> task is the last to be executed, and, if I comment the line where
> it's .delay method is called, the folder is successfully associated
> with the object!
>    This obviously means that somehow the object without any
> association (just created) is what each task sees, even though I am
> refetching it from the db, and thus the calendar task is overwriting
> whatever the folder task just did with the object. I even used the
> lock idea proposed here:http://ask.github.com/celery/cookbook/tasks.html#ensuring-a-task-is-o...
> to no avail, as both are done in sequence.
> I thought that celery was going to make my life easy letting this kind
> of stuff be done asynchronously and safely, but this has let me
> thinking of going back to slow albeit trustworthy response times in my
> app :(
>
> I'd appreciate any pointers you could give me :D

--

-- 
You received this message because you are subscribed to the Google Groups "celery-users" group.
To post to this group, send email to celery-users@...
To unsubscribe from this group, send email to celery-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/celery-users?hl=en.


Gmane