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.
remotes/1693045480750635534/spooky-22
Snakes 2022-06-07 06:57:26 -04:00
parent aaeb09fd91
commit acb3a0b338
4 changed files with 29 additions and 0 deletions

1
env
View File

@ -1,3 +1,4 @@
export FLASK_APP="/service/files/cli:app"
export MASTER_KEY="blahblahblah"
export DOMAIN="localhost"
export SITE_NAME="rDrama"

View File

10
files/cli.py 100644
View File

@ -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)

View File

@ -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