Download Celery Documentation
Transcript
Celery Documentation, Release 3.0.24 >>> state(’PROGRESS’) > state(STARTED) True >>> state(’PROGRESS’) > state(’SUCCESS’) False 2.13.26 celery.contrib.abortable • Abortable tasks overview – Usage example Abortable tasks overview For long-running Task‘s, it can be desirable to support aborting during execution. Of course, these tasks should be built to support abortion specifically. The AbortableTask serves as a base class for all Task objects that should support abortion by producers. • Producers may invoke the abort() method on AbortableAsyncResult instances, to request abortion. • Consumers (workers) should periodically check (and honor!) the is_aborted() method at controlled points in their task’s run() method. The more often, the better. The necessary intermediate communication is dealt with by the AbortableTask implementation. Usage example In the consumer: from celery.contrib.abortable import AbortableTask from celery.utils.log import get_task_logger logger = get_logger(__name__) class MyLongRunningTask(AbortableTask): def run(self, **kwargs): results = [] for x in xrange(100): # Check after every 5 loops.. if x % 5 == 0: # alternatively, check when some timer is due if self.is_aborted(**kwargs): # Respect the aborted status and terminate # gracefully logger.warning(’Task aborted.’) return y = do_something_expensive(x) results.append(y) logger.info(’Task finished.’) return results In the producer: 2.13. API Reference 269
Related documents
3.0 PDF - Read the Docs
Celery Documentation
2.5-archived PDF
2.4-archived PDF
Celery Documentation
2.3-archived PDF
Celery Documentation
1.0-archived PDF
1.x PDF - Read the Docs
Shiatsu Diploma Study Manual © John Lewis 2005 1 GENERAL
SeaShark Detailed Design Document
OpenStack Image Service Admin Manual