I am trying to figure out how to change the result displayed in Django's admin task section so that I can see when a condition is hit within a task. I do not want the task to fail, I want a new state that I can see and query. When I try to update_state(state="CUSTOM"), the task completes without error (which is good) but doesn't affect the state displayed in django admin.

I have had no luck finding the example referenced in the documentation pertaining to custom states and have read numerous blogs and posts and sifted through different parts of the documentation to no avail - and have even tried the unreponsive irc chat room so I am out of ideas.

Any help or ideas would be much appreciated.

asked 25 Mar '11, 13:47

newbie10011100's gravatar image

newbie10011100
112
accept rate: 0%

edited 25 Mar '11, 13:49

We would need to see some of the code involved to be able to speculate on what is going on.

(25 Mar '11, 13:54) johns ♦♦ johns's gravatar image

There is nothing complex about it, though I'm obviously not doing the last line correctly.

Here is the most basic simplification of the task:

from celery.decorators import task @task() def myTask(id): instance = TableModel.objects.get(id=id) status = call_another_method(instance) if status == some_code: myTask.update_state(state="CUSTOM")


the task is called in a django model save method like so: myTask.delay(self.id)

Eagerly awaiting any insight into getting this to work.

Thanks!

(25 Mar '11, 14:00) newbie10011100 newbie10011100's gravatar image

According to the celery official docs,

http://ask.github.com/celery/userguide/tasks.html#custom-states

The function requires other parameters, 'current' and 'total'. Your code example does not show those, it is possible you need to add them.

link

answered 25 Mar '11, 14:33

johns's gravatar image

johns ♦♦
4.1k28
accept rate: 23%

Yeah, I had supplied an additional meta dictionary param (state= 'CUSTOM', meta={}) and that didn't change the outcome. I believe the current and total keys are used for whatever is querying state to build the progress bar. I am beginning to think that the state can only be modified while the task is running and once it is completed - celery changes the state to whatever it deems is the outcome. While I wait for facts, I am going to raise an error and return a string with a description (the text displays django admin's task detail). Any task calls without 'delay' will be wrapped in a try/excep

(25 Mar '11, 14:45) newbie10011100 newbie10011100's gravatar image

See answer posted in thread here:

http://groups.google.com/group/celery-users/browse_thread/thread/165e5c5743653db1?hl=en#

link

answered 28 Mar '11, 07:29

newbie10011100's gravatar image

newbie10011100
112
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×742
×16
×4
×1

Asked: 25 Mar '11, 13:47

Seen: 2,635 times

Last updated: 23 Apr '11, 14:08

Plans & prices    Sign up    Why WebFaction?    Contact us    Affiliate program    Support    Legal    Jobs    Blog    Control panel login
Powered by OSQA
© Copyright 2003-2012 Swarma Limited - WebFaction is a service of Swarma Limited