Python celery.signals() Examples

The following are 4 code examples of celery.signals(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module celery , or try the search function .
Example #1
Source File: worker.py    From celerytest with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def on_event(self, event):
        # maintain state
        self.state.event(event)

        # only need to update state when something relevant to pending tasks is happening
        check_states = ['task-received','task-started','task-succeeded','task-failed','task-revoked']
        if not event['type'] in check_states:
            return

        active = len(self.immediate_pending_tasks) > 0
        
        # switch signals if needed
        if active and self.idle.is_set():
            self.idle.clear()
            self.active.set()
        elif not active and self.active.is_set():
            self.idle.set()
            self.active.clear() 
Example #2
Source File: test_celery.py    From scout_apm_python with MIT License 5 votes vote down vote up
def do_nothing(**kwargs):
    # Just by connecting to this signal, we prevent Celery from setting up
    # logging - and stop it from interfering with global state
    # http://docs.celeryproject.org/en/v4.3.0/userguide/signals.html#setup-logging
    pass 
Example #3
Source File: worker.py    From celerytest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def run(self):
        signals.worker_init.connect(self.on_worker_init)
        signals.worker_ready.connect(self.on_worker_ready)

        self.monitor.daemon = self.daemon
        self.monitor.start()

        worker = self.app.Worker()
        if hasattr(worker, 'start'):
            worker.start()
        elif hasattr(worker, 'run'):
            worker.run()
        else:
            raise Exception("Don't know how to start worker. Incompatible Celery?") 
Example #4
Source File: worker.py    From celerytest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def stop(self):
        self.monitor.stop()

        for c in self.consumers:
            c.stop()
        
        for w in self.workers:
            w.terminate()
        
        signals.worker_init.disconnect(self.on_worker_init)
        signals.worker_ready.disconnect(self.on_worker_ready)