@@ -0,0 +1,1898 @@
+import json%0A%0Aimport celery.beat%0Aimport sqlalchemy as sqla%0Afrom sqlalchemy import orm%0A%0Afrom . import model%0A%0A%0Aclass SQLAlchemyScheduler(celery.beat.Scheduler):%0A%0A    database_url = 'sqlite:///data.sqlite'%0A%0A    _session = None%0A%0A    @property%0A    def session(self):%0A        if self._session is None:%0A            engine = sqla.create_engine(self.database_url)%0A            Session = orm.sessionmaker(bind=engine)%0A            self._session = Session()%0A        return self._session%0A%0A    def get_periodic_tasks(self):%0A        for periodic_task in self.session.query(model.PeriodicTask):%0A            yield periodic_task.name, dict(%0A                task=periodic_task.task,%0A                schedule=periodic_task.schedule,%0A                args=json.loads(periodic_task.args or 'null'),%0A                kwargs=json.loads(periodic_task.kwargs or 'null'),%0A                options=dict(%0A                    queue=periodic_task.queue,%0A                    exchange=periodic_task.exchange,%0A                    routing_key=periodic_task.routing_key,%0A                    expires=periodic_task.expires,%0A                ),%0A            )%0A%0A    def setup_schedule(self):%0A        super(SQLAlchemyScheduler, self).setup_schedule()%0A        self.merge_inplace(dict(self.get_periodic_tasks()))%0A%0A    def sync(self):%0A        super(SQLAlchemyScheduler, self).sync()%0A        for name, entry in self.schedule.items():%0A            task = self.session.query(model.PeriodicTask).filter(%0A                model.PeriodicTask.name == name%0A            ).first()%0A            if task is not None:%0A                task.last_run_at = entry.last_run_at%0A                task.total_run_count = entry.total_run_count%0A        self.session.commit()%0A%0A    def close(self):%0A        super(SQLAlchemyScheduler, self).close()%0A        if self._session is not None:%0A            self.logger.debug('Closing database connection')%0A            self.session.close()%0A

add custom scheduler