def test_run(self): prev = app.backend app.backend.cleanup = Mock() app.backend.cleanup.__name__ = 'cleanup' try: cleanup_task = builtins.add_backend_cleanup_task(app) cleanup_task() self.assertTrue(app.backend.cleanup.called) finally: app.backend = prev
def setup_periodic_tasks(sender, **kwargs): from materializationengine.workflows.periodic_database_removal import ( remove_expired_databases, ) from materializationengine.workflows.update_database_workflow import ( run_periodic_database_update, ) from materializationengine.workflows.periodic_materialization import ( run_periodic_materialization) periodic_tasks = { "run_daily_periodic_materialization": run_periodic_materialization.s(days_to_expire=2), "run_weekly_periodic_materialization": run_periodic_materialization.s(days_to_expire=7), "run_lts_periodic_materialization": run_periodic_materialization.s(days_to_expire=30), "run_periodic_database_update": run_periodic_database_update.s(), "remove_expired_databases": remove_expired_databases.s( delete_threshold=os.environ.get('MIN_DATABASES', 3)), } # remove expired task results in redis broker sender.add_periodic_task( crontab(hour=0, minute=0, day_of_week="*", day_of_month="*", month_of_year="*"), add_backend_cleanup_task(celery), name="Clean up back end results", ) beat_schedules = celery.conf["BEAT_SCHEDULES"] celery_logger.info(beat_schedules) schedules = CeleryBeatSchema(many=True).dump(beat_schedules) for schedule in schedules: if schedule["task"] not in periodic_tasks: raise TaskNotFound(schedule["task"], periodic_tasks) task = periodic_tasks[schedule["task"]] sender.add_periodic_task( crontab( minute=schedule["minute"], hour=schedule["hour"], day_of_week=schedule["day_of_week"], day_of_month=schedule["day_of_month"], month_of_year=schedule["month_of_year"], ), task, name=schedule["name"], )
def test_run(self): self.app.backend.cleanup = Mock() self.app.backend.cleanup.__name__ = 'cleanup' cleanup_task = builtins.add_backend_cleanup_task(self.app) cleanup_task() self.app.backend.cleanup.assert_called()
def test_run(self): self.app.backend.cleanup = Mock() self.app.backend.cleanup.__name__ = 'cleanup' cleanup_task = builtins.add_backend_cleanup_task(self.app) cleanup_task() self.assertTrue(self.app.backend.cleanup.called)
def test_run(self): self.app.backend.cleanup = Mock() self.app.backend.cleanup.__name__ = "cleanup" cleanup_task = builtins.add_backend_cleanup_task(self.app) cleanup_task() self.assertTrue(self.app.backend.cleanup.called)