fire and "forget" in a view

77 views
Skip to first unread message

Christian Schulz

unread,
Dec 20, 2013, 6:11:53 AM12/20/13
to django...@googlegroups.com
Hi,

in my views i have  method calls which might be take some time. It is sufficient to return a simple message and request
the result in another step.

I explore celery , but It might be to complex , because I have to use class based task an have some difficulties  
with the serializer's in different ways.

Know somebody a different strategy/simple lib?

Thanks in advance
Christian

Erik Cederstrand

unread,
Dec 20, 2013, 6:57:10 AM12/20/13
to Django Users
Long-running processes do not belong in HTTP requests. You really want to move this to a separate process outside the web server.

Celery is the obvious choice as you will find lots of tutorials for Django, but depending on your use-case you could store the job in the database, and run a custom management command via cron once every minute to check if there is anything to do.

If you are having problems serializing, try to just pass the primary key(s) of whatever object(s) you want to process. Then have the task load these objects from the database.

Erik

Tom Evans

unread,
Dec 20, 2013, 8:57:16 AM12/20/13
to django...@googlegroups.com
On Fri, Dec 20, 2013 at 11:11 AM, Christian Schulz
<mining...@gmail.com> wrote:
> Hi,
>
> in my views i have method calls which might be take some time. It is
> sufficient to return a simple message and request
> the result in another step.
>
> I explore celery , but It might be to complex , because I have to use class
> based task an have some difficulties
> with the serializer's in different ways.

Celery is not too complex, it is just complex enough! You should use
celery over any sort of ghetto queue, since you will get management
and process control that otherwise may be missing or require you to
write yourself. Anything you have to write yourself distracts you from
writing the features that you actually desire in your site.

With respect to serialization, if this is something that can be
initiated from a view, then this must mean that the arguments are
easily serializable, since the arguments have already been serialised
into POST or GET arguments as strings.

Cheers

Tom

Christian Schulz

unread,
Dec 20, 2013, 11:33:14 AM12/20/13
to django...@googlegroups.com, teva...@googlemail.com
Hi Tom + Erik,
Thanks to reinforce using celery. After some tutorials  I realize that's the best option.
Cheers  Christian
Reply all
Reply to author
Forward
0 new messages