import logging from .models import Subscription, ACTIVE_BACKENDS logger = logging.getLogger(__name__) from celery import task @task def check_subscriptions(): logger.debug("checking subscriptions") subs = Subscription.objects.filter(status='active', backend_id='stripe').all() for sub in subs: logger.debug("checking subscription #%s on %s", sub.id, sub.backend_id) sub.refresh_from_db() ACTIVE_BACKENDS['stripe'].refresh_subscription(sub) sub.save()