From acb3a0b3386aaff139e283c0ec670c48c4ffa618 Mon Sep 17 00:00:00 2001 From: TLSM Date: Tue, 7 Jun 2022 06:57:26 -0400 Subject: [PATCH] Enable flask command, add cron target. Adding an empty __init__.py, the imports-only cli.py, and setting FLASK_APP in the environment are enough to get the `flask` command to work. This will enable future changes, including database migrations. The proximate reason for the fix is to add a `flask cron` command to run scheduled tasks within the application from cron. Specifically, the lottery should be run from cron. --- env | 1 + files/__init__.py | 0 files/cli.py | 10 ++++++++++ files/helpers/cron.py | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 files/__init__.py create mode 100644 files/cli.py create mode 100644 files/helpers/cron.py diff --git a/env b/env index a9192d3cf..5df6a5920 100644 --- a/env +++ b/env @@ -1,3 +1,4 @@ +export FLASK_APP="/service/files/cli:app" export MASTER_KEY="blahblahblah" export DOMAIN="localhost" export SITE_NAME="rDrama" diff --git a/files/__init__.py b/files/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/files/cli.py b/files/cli.py new file mode 100644 index 000000000..85cbf5b6f --- /dev/null +++ b/files/cli.py @@ -0,0 +1,10 @@ +from .__main__ import app, db_session +from flask import g +import files.helpers.cron + +#from flask_migrate import Migrate +#from flask_sqlalchemy import SQLAlchemy +#import files.classes + +#db = SQLAlchemy(app) +#migrate = Migrate(app, db) diff --git a/files/helpers/cron.py b/files/helpers/cron.py new file mode 100644 index 000000000..f748a3bd1 --- /dev/null +++ b/files/helpers/cron.py @@ -0,0 +1,18 @@ +from files.cli import g, app, db_session +import click +import files.helpers.lottery + +@app.cli.command('cron', help='Run scheduled tasks.') +@click.option('--every-5m', is_flag=True, help='Call every 5 minutes.') +@click.option('--every-1h', is_flag=True, help='Call every 1 hour.') +@click.option('--every-1d', is_flag=True, help='Call every 1 day.') +def cron(every_5m, every_1h, every_1d): + g.db = db_session() + + if every_5m: + pass + if every_1h: + pass + if every_1d: + pass +