mirror of
https://github.com/simple-login/app.git
synced 2025-02-24 07:43:54 +08:00
support --job argument in cron: stats, notify_trial_end
This commit is contained in:
parent
e29021f46a
commit
3cbaab41f3
1 changed files with 17 additions and 3 deletions
20
cron.py
20
cron.py
|
@ -1,3 +1,5 @@
|
||||||
|
import argparse
|
||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
|
|
||||||
from app.config import IGNORED_EMAILS, ADMIN_EMAIL
|
from app.config import IGNORED_EMAILS, ADMIN_EMAIL
|
||||||
|
@ -16,7 +18,7 @@ from app.models import (
|
||||||
from server import create_app
|
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():
|
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):
|
if arrow.now().shift(days=3) > user.trial_end >= arrow.now().shift(days=2):
|
||||||
LOG.d("Send trial end email to user %s", user)
|
LOG.d("Send trial end email to user %s", user)
|
||||||
|
@ -106,8 +108,20 @@ nb_app: {nb_app} <br>
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
LOG.d("Start running cronjob")
|
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()
|
app = create_app()
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
stats()
|
if args.job == "stats":
|
||||||
send_trial_end_soon()
|
stats()
|
||||||
|
elif args.job == "notify_trial_end":
|
||||||
|
notify_trial_end()
|
||||||
|
|
Loading…
Reference in a new issue