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

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.


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

According to the celery official docs,


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

permanent link

answered 25 Mar '11, 14:33

johns's gravatar image

johns ♦♦
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:


permanent link

answered 28 Mar '11, 07:29

newbie10011100's gravatar image

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



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

Question tags:


question asked: 25 Mar '11, 13:47

question was seen: 3,798 times

last updated: 23 Apr '11, 14:08

Features & prices    Sign up    Contact us    Affiliate program    Support    Legal    Jobs    Blog    Control panel login
© Copyright 2003-2015 Swarma Limited - WebFaction is a service of Swarma Limited