add poll_apple_subscription(), call it everyday
This commit is contained in:
parent
1bba38edb6
commit
71d53d16da
16
cron.py
16
cron.py
|
@ -3,6 +3,7 @@ import argparse
|
||||||
import arrow
|
import arrow
|
||||||
|
|
||||||
from app import s3
|
from app import s3
|
||||||
|
from app.api.views.apple import verify_receipt
|
||||||
from app.config import IGNORED_EMAILS, ADMIN_EMAIL
|
from app.config import IGNORED_EMAILS, ADMIN_EMAIL
|
||||||
from app.email_utils import send_email, send_trial_end_soon_email, render
|
from app.email_utils import send_email, send_trial_end_soon_email, render
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
|
@ -17,6 +18,7 @@ from app.models import (
|
||||||
Client,
|
Client,
|
||||||
ManualSubscription,
|
ManualSubscription,
|
||||||
RefusedEmail,
|
RefusedEmail,
|
||||||
|
AppleSubscription,
|
||||||
)
|
)
|
||||||
from server import create_app
|
from server import create_app
|
||||||
|
|
||||||
|
@ -105,6 +107,16 @@ def notify_manual_sub_end():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def poll_apple_subscription():
|
||||||
|
"""Poll Apple API to update AppleSubscription"""
|
||||||
|
# todo: only near the end of the subscription
|
||||||
|
for apple_sub in AppleSubscription.query.all():
|
||||||
|
user = apple_sub.user
|
||||||
|
verify_receipt(apple_sub.receipt_data, user)
|
||||||
|
|
||||||
|
LOG.d("Finish poll_apple_subscription")
|
||||||
|
|
||||||
|
|
||||||
def stats():
|
def stats():
|
||||||
"""send admin stats everyday"""
|
"""send admin stats everyday"""
|
||||||
if not ADMIN_EMAIL:
|
if not ADMIN_EMAIL:
|
||||||
|
@ -206,6 +218,7 @@ if __name__ == "__main__":
|
||||||
"notify_manual_subscription_end",
|
"notify_manual_subscription_end",
|
||||||
"notify_premium_end",
|
"notify_premium_end",
|
||||||
"delete_refused_emails",
|
"delete_refused_emails",
|
||||||
|
"poll_apple_subscription"
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -228,3 +241,6 @@ if __name__ == "__main__":
|
||||||
elif args.job == "delete_refused_emails":
|
elif args.job == "delete_refused_emails":
|
||||||
LOG.d("Deleted refused emails")
|
LOG.d("Deleted refused emails")
|
||||||
delete_refused_emails()
|
delete_refused_emails()
|
||||||
|
elif args.job == "poll_apple_subscription":
|
||||||
|
LOG.d("Poll Apple Subscriptions")
|
||||||
|
poll_apple_subscription()
|
||||||
|
|
|
@ -28,3 +28,9 @@ jobs:
|
||||||
shell: /bin/bash
|
shell: /bin/bash
|
||||||
schedule: "0 11 * * *"
|
schedule: "0 11 * * *"
|
||||||
captureStderr: true
|
captureStderr: true
|
||||||
|
|
||||||
|
- name: SimpleLogin Poll Apple Subscriptions
|
||||||
|
command: python /code/cron.py -j poll_apple_subscription
|
||||||
|
shell: /bin/bash
|
||||||
|
schedule: "0 12 * * *"
|
||||||
|
captureStderr: true
|
||||||
|
|
Loading…
Reference in New Issue