From 7f6a45a5b665df3da9370a5bef1dbc126326b8ef Mon Sep 17 00:00:00 2001 From: Aevann Date: Sat, 22 Jul 2023 20:11:07 +0300 Subject: [PATCH] run cron in localhost too --- files/helpers/cron.py | 11 +++++++---- files/routes/__init__.py | 5 +++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/files/helpers/cron.py b/files/helpers/cron.py index d25586637f..6432905c4f 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -26,10 +26,7 @@ from files.cli import app, db_session, g CRON_CACHE_TIMEOUT = 172800 -@app.cli.command('cron', help='Run scheduled tasks.') -@click.option('--every-5m', is_flag=True, help='Call every 5 minutes.') -@click.option('--every-1d', is_flag=True, help='Call every 1 day.') -def cron(every_5m, every_1d): +def cron_fn(every_5m, every_1d): g.db = db_session() g.v = None @@ -67,6 +64,12 @@ def cron(every_5m, every_1d): print(f'Finished {kind} at {now}', flush=True) stdout.flush() +@app.cli.command('cron', help='Run scheduled tasks.') +@click.option('--every-5m', is_flag=True, help='Call every 5 minutes.') +@click.option('--every-1d', is_flag=True, help='Call every 1 day.') +def cron(every_5m, every_1d): + cron_fn(every_5m, every_1d) + def _sub_inactive_purge_task(): if not HOLE_INACTIVITY_DELETION: return False diff --git a/files/routes/__init__.py b/files/routes/__init__.py index 0035d85238..1cf41c517d 100644 --- a/files/routes/__init__.py +++ b/files/routes/__init__.py @@ -49,3 +49,8 @@ if FEATURES['ASSET_SUBMISSIONS']: from .push_notifs import * if FEATURES['PING_GROUPS']: from .groups import * + +if IS_LOCALHOST: + from files.helpers.cron import cron_fn + with app.app_context(): + cron_fn(True, False)