Example #1
0
class CeleryDriverBeat(CeleryDriver):

    def _setup_logging(self, *args, **kwargs):
        from logging.config import dictConfig
        dictConfig(get_logging_config(self.config))

    def _prepare(self):
        uvloop.install()

        self._app = Celery(self.config.BEAT_BLUEPRINT)
        self._app.conf.update(self.config.get_beat_config())

        # Setup celery signals
        signals.setup_logging.connect(self._setup_logging)

        for method in self._methods:
            if method.schedule is None:
                continue

            self._app._add_periodic_task(method.name, method.schedule.entry(self._get_name_task(method.name)))

    def run(self, *args, **kwargs):
        self._prepare()

        self.loop.run_until_complete(self._call_hooks(CeleryHookNames.before_beat_start))

        try:
            self._app.Beat().run()
        except Exception as e:
            print(e)
        finally:
            self.loop.run_until_complete(self._call_hooks(CeleryHookNames.after_beat_start))