PolicyStat / jobtastic

Make your user-responsive long-running Celery jobs totally awesomer.
http://policystat.github.com/jobtastic/
MIT License
644 stars 61 forks source link

Add a helper for notifying (emailing?) the result of a task to a user on completion #2

Open winhamwr opened 12 years ago

winhamwr commented 12 years ago

For really long-running tasks, even a progress bar isn't all that user friendly. It still requires them to hang around with a browser window open. A really nice feature would be the ability to let users opt-in to some kind of notification when their task is done.

Jobtastic can do this with a keyword argument on the task combined with a JobtasticNotifierTask. The idea would be to add something like

allow_user_notification = True

on the task. Then, with a supplied Django View or Flask request handler, the user can opt in to being notified about the task from the page where they're waiting for results. When the original JobtasticTask finishes, it checks a known cache location (based off of cache_prefix) to see if any users have opted in to notifications. If they have, it fires off a JobtasticNotifierTask right before it was finished.

This task then checks the same cache location and uses the configured JOBTASTIC_NOTIFICATION_BACKENDS to notify the given user.

We can probably start with these backends for good coverage of common use-cases: