mirror of
https://github.com/simple-login/app.git
synced 2024-11-10 09:13:45 +08:00
add poll_apple_subscription(), call it everyday
This commit is contained in:
parent
1bba38edb6
commit
71d53d16da
2 changed files with 22 additions and 0 deletions
16
cron.py
16
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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue