72f96e3c02
- Fix platform-specific %%-d format → use .day and .year directly in templates and messages
- Fix Tailwind JIT dynamic class interpolation → use static class variables in showFlash()
- Fix Jinja pending_date rendering → use .strftime('%B') + .day + .year
- Add aria-atomic=true to flash container for full screen-reader announcements
- Move SessionLocal() creation inside try block in Celery task for proper session management
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
"""Celery task to apply pending subscription changes that have become due.
|
|
|
|
Runs daily to ensure that scheduled downgrades are applied on time.
|
|
"""
|
|
|
|
import logging
|
|
|
|
from app.celery_app import celery
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@celery.task(name="app.tasks.subscription_tasks.apply_pending_subscription_changes_all")
|
|
def apply_pending_subscription_changes_all() -> dict[str, int]:
|
|
"""Apply all pending subscription changes whose effective date has arrived.
|
|
|
|
Iterates over every ``UserProfile`` that has a pending change and calls
|
|
:func:`app.utils.subscription.apply_pending_subscription_changes` for
|
|
each one.
|
|
|
|
Returns:
|
|
A dict with ``{"applied": <count>, "checked": <count>}``.
|
|
"""
|
|
from app.database import SessionLocal
|
|
from app.models import UserProfile
|
|
from app.utils.subscription import apply_pending_subscription_changes
|
|
|
|
applied = 0
|
|
checked = 0
|
|
db = SessionLocal()
|
|
try:
|
|
profiles = (
|
|
db.query(UserProfile)
|
|
.filter(
|
|
UserProfile.subscription_change_pending_tier.isnot(None),
|
|
UserProfile.subscription_change_pending_date.isnot(None),
|
|
)
|
|
.all()
|
|
)
|
|
for profile in profiles:
|
|
checked += 1
|
|
if apply_pending_subscription_changes(db, profile.user_id):
|
|
applied += 1
|
|
except Exception as exc:
|
|
logger.error("Error in apply_pending_subscription_changes_all: %s", exc)
|
|
finally:
|
|
db.close()
|
|
|
|
logger.info("apply_pending_subscription_changes_all: checked=%d applied=%d", checked, applied)
|
|
return {"checked": checked, "applied": applied}
|