diff --git a/cron.py b/cron.py index 651092c6..c63d5c57 100644 --- a/cron.py +++ b/cron.py @@ -3,6 +3,7 @@ import argparse import arrow from app import s3 +from app.api.views.apple import verify_receipt from app.config import IGNORED_EMAILS, ADMIN_EMAIL from app.email_utils import send_email, send_trial_end_soon_email, render from app.extensions import db @@ -17,6 +18,7 @@ from app.models import ( Client, ManualSubscription, RefusedEmail, + AppleSubscription, ) 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(): """send admin stats everyday""" if not ADMIN_EMAIL: @@ -206,6 +218,7 @@ if __name__ == "__main__": "notify_manual_subscription_end", "notify_premium_end", "delete_refused_emails", + "poll_apple_subscription" ], ) args = parser.parse_args() @@ -228,3 +241,6 @@ if __name__ == "__main__": elif args.job == "delete_refused_emails": LOG.d("Deleted refused emails") delete_refused_emails() + elif args.job == "poll_apple_subscription": + LOG.d("Poll Apple Subscriptions") + poll_apple_subscription() diff --git a/crontab.yml b/crontab.yml index 0c453757..fc61a44f 100644 --- a/crontab.yml +++ b/crontab.yml @@ -28,3 +28,9 @@ jobs: shell: /bin/bash schedule: "0 11 * * *" captureStderr: true + + - name: SimpleLogin Poll Apple Subscriptions + command: python /code/cron.py -j poll_apple_subscription + shell: /bin/bash + schedule: "0 12 * * *" + captureStderr: true