support --job argument in cron: stats, notify_trial_end

This commit is contained in:
Son NK 2020-02-02 22:17:04 +07:00
parent e29021f46a
commit 3cbaab41f3
1 changed files with 17 additions and 3 deletions

20
cron.py
View File

@ -1,3 +1,5 @@
import argparse
import arrow
from app.config import IGNORED_EMAILS, ADMIN_EMAIL
@ -16,7 +18,7 @@ from app.models import (
from server import create_app
def send_trial_end_soon():
def notify_trial_end():
for user in User.query.filter(User.trial_end.isnot(None)).all():
if arrow.now().shift(days=3) > user.trial_end >= arrow.now().shift(days=2):
LOG.d("Send trial end email to user %s", user)
@ -106,8 +108,20 @@ nb_app: {nb_app} <br>
if __name__ == "__main__":
LOG.d("Start running cronjob")
parser = argparse.ArgumentParser()
parser.add_argument(
"-j",
"--job",
help="Choose a cron job to run",
type=str,
choices=["stats", "notify_trial_end",],
)
args = parser.parse_args()
app = create_app()
with app.app_context():
stats()
send_trial_end_soon()
if args.job == "stats":
stats()
elif args.job == "notify_trial_end":
notify_trial_end()