def __init__(self, main=None, loader=None, backend=None, amqp=None, events=None, log=None, control=None, set_as_current=True, accept_magic_kwargs=False, tasks=None, broker=None, **kwargs): self.clock = LamportClock() self.main = main self.amqp_cls = amqp or self.amqp_cls self.backend_cls = backend or self.backend_cls self.events_cls = events or self.events_cls self.loader_cls = loader or self.loader_cls self.log_cls = log or self.log_cls self.control_cls = control or self.control_cls self.set_as_current = set_as_current self.registry_cls = self.registry_cls if tasks is None else tasks self.accept_magic_kwargs = accept_magic_kwargs self.finalized = False self._pending = deque() self._tasks = instantiate(self.registry_cls) # these options are moved to the config to # simplify pickling of the app object. self._preconf = {} if broker: self._preconf["BROKER_URL"] = broker if self.set_as_current: self.set_current() self.on_init()
def start(self, argv=None): """Run :program:`celery` using `argv`. Uses :data:`sys.argv` if `argv` is not specified. """ return instantiate("celery.bin.celery:CeleryCommand", app=self).execute_from_commandline(argv)
def evcam(camera, freq=1.0, maxrate=None, loglevel=0, logfile=None, pidfile=None, timer=None, app=None): app = app_or_default(app) if pidfile: pidlock = platforms.create_pidlock(pidfile).acquire() atexit.register(pidlock.release) if not isinstance(loglevel, int): loglevel = LOG_LEVELS[loglevel.upper()] logger = app.log.setup_logger(loglevel=loglevel, logfile=logfile, name="celery.evcam") logger.info( "-> evcam: Taking snapshots with %s (every %s secs.)\n" % ( camera, freq)) state = app.events.State() cam = instantiate(camera, state, app=app, freq=freq, maxrate=maxrate, logger=logger, timer=timer) cam.install() conn = app.broker_connection() recv = app.events.Receiver(conn, handlers={"*": state.event}) try: try: recv.capture(limit=None) except KeyboardInterrupt: raise SystemExit finally: cam.cancel() conn.close()
def worker_main(self, argv=None): """Run :program:`celery worker` using `argv`. Uses :data:`sys.argv` if `argv` is not specified. """ return instantiate("celery.bin.worker:worker", app=self).execute_from_commandline(argv)
def evcam(camera, freq=1.0, maxrate=None, loglevel=0, logfile=None, pidfile=None, timer=None, app=None): """Start snapshot recorder.""" app = app_or_default(app) if pidfile: platforms.create_pidlock(pidfile) app.log.setup_logging_subsystem(loglevel, logfile) print('-> evcam: Taking snapshots with {0} (every {1} secs.)'.format( camera, freq)) state = app.events.State() cam = instantiate(camera, state, app=app, freq=freq, maxrate=maxrate, timer=timer) cam.install() conn = app.connection_for_read() recv = app.events.Receiver(conn, handlers={'*': state.event}) try: try: recv.capture(limit=None) except KeyboardInterrupt: raise SystemExit finally: cam.cancel() conn.close()
def evcam(camera, freq=1.0, maxrate=None, loglevel=0, logfile=None, pidfile=None, timer=None, app=None): app = app_or_default(app) if pidfile: platforms.create_pidlock(pidfile) app.log.setup_logging_subsystem(loglevel, logfile) logger.info( "-> evcam: Taking snapshots with %s (every %s secs.)\n" % ( camera, freq)) state = app.events.State() cam = instantiate(camera, state, app=app, freq=freq, maxrate=maxrate, timer=timer) cam.install() conn = app.broker_connection() recv = app.events.Receiver(conn, handlers={"*": state.event}) try: try: recv.capture(limit=None) except KeyboardInterrupt: raise SystemExit finally: cam.cancel() conn.close()
def beat(): """ Start running celerybeat """ import sys from celery.utils.imports import instantiate if len(sys.argv) < 2: print "usage: %s config.yaml [celery opts]" % sys.argv[0] sys.exit(1) init_celery(sys.argv.pop(1)) try: instantiate( 'celery.bin.celerybeat:BeatCommand', app=celery).execute_from_commandline(sys.argv) except ImportError: instantiate( 'celery.bin.beat:beat', app=celery).execute_from_commandline(sys.argv)
def add_actor(self, actor_name, actor_id): """Add actor to the actor registry and start the actor main method""" try: actor = instantiate(actor_name, connection = self.connection, id = actor_id) consumer = actor.Consumer(self.connection.channel()) consumer.consume() self.actor_registry[actor.id] = consumer info('Register actor in the actor registry: %s' % actor_name) return actor.id except Exception as exc: error('Start actor error: %r', exc, exc_info=True)
def add_actor(self, name, id = None): """Add actor to the actor registry and start the actor's main method""" try: actor = instantiate(name, connection = self.connection, id = id) self._start_actor_consumer(actor) if actor.id in self.actor_registry: warn('Actor with the same id already exists') debug('Register actor in the actor registry: %s' % name) return actor.id except Exception as exc: error('Start actor error: %r', exc, exc_info=True)
def start_strategy(self, app, consumer, **kwargs): return instantiate(self.Strategy, self, app, consumer, **kwargs)
def worker_main(self, argv=None): return instantiate( 'celery.bin.worker:worker', app=self).execute_from_commandline(argv)
def amqp(self): """AMQP related functionality: :class:`~@amqp`.""" return instantiate(self.amqp_cls, app=self)
def events(self): """Consuming and sending events: :class:`~@events`.""" return instantiate(self.events_cls, app=self)
def instantiate(self, qualname, *args, **kwargs): return instantiate(qualname, *args, **kwargs)
def __new__(cls, *args, **kwargs): return instantiate(options.auth_provider, *args, **kwargs)
def worker_main(self, argv=None): return instantiate("celery.bin.celeryd:WorkerCommand", app=self) \ .execute_from_commandline(argv)
def start(self, argv=None): return instantiate("celery.bin.celery:CeleryCommand", app=self) \ .execute_from_commandline(argv)
def log(self): """Logging: :class:`~@log`.""" return instantiate(self.log_cls, app=self)
def control(self): """Remote control: :class:`~@control`.""" return instantiate(self.control_cls, app=self)
def control(self): return instantiate(self.control_cls, app=self)
def amqp(self): """Sending/receiving messages. See :class:`~celery.app.amqp.AMQP`.""" return instantiate(self.amqp_cls, app=self)
def log(self): return instantiate(self.log_cls, app=self)
def events(self): return instantiate(self.events_cls, app=self)
def worker_main(self, argv=None): return instantiate('celery.bin.worker:worker', app=self).execute_from_commandline(argv)
def start_group(actor_type, count): actor_group = [] [actor_group.append(instantiate(actor_type)) for _ in range(0, count)] wf = Workflow(actor_group) remote_group = list(wf.start()) return remote_group
def worker_main(self, argv=None): return instantiate('celery.bin.celeryd:WorkerCommand', app=self) \ .execute_from_commandline(argv)
def control(self): """Controlling worker nodes. See :class:`~celery.app.control.Control`.""" return instantiate(self.control_cls, app=self)
def log(self): """Logging utilities. See :class:`~celery.app.log.Logging`.""" return instantiate(self.log_cls, app=self)
def start(self, argv=None): return instantiate( 'celery.bin.celery:CeleryCommand', app=self).execute_from_commandline(argv)
def amqp(self): return instantiate(self.amqp_cls, app=self)
def events(self): """Sending/receiving events. See :class:`~celery.events.Events`. """ return instantiate(self.events_cls, app=self)