Spaces:
Running
Running
Download backend/subscription_cron.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 1.95 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/subscription_cron.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/subscription_cron.py
-
curl -L -o subscription_cron.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/subscription_cron.py
1.95 kB
| """ | |
| Subscription Renewal CRON Job | |
| Run this daily to process recurring subscription payments. | |
| Usage: | |
| python subscription_cron.py | |
| Or schedule via system cron: | |
| 0 2 * * * cd /path/to/backend && python subscription_cron.py | |
| """ | |
| import asyncio | |
| import sys | |
| from pathlib import Path | |
| # Add parent directory to path | |
| sys.path.insert(0, str(Path(__file__).parent)) | |
| import httpx | |
| from datetime import datetime | |
| async def trigger_renewal_job(): | |
| """Trigger the renewal API endpoint.""" | |
| print(f"\n{'='*80}") | |
| print(f"π CRON JOB STARTED: {datetime.utcnow().isoformat()}") | |
| print(f"{'='*80}\n") | |
| api_url = "http://localhost:8000/api/v1/billing/renewals/process" | |
| try: | |
| async with httpx.AsyncClient(timeout=300.0) as client: # 5 min timeout | |
| print(f"π‘ Calling API: {api_url}") | |
| response = await client.post(api_url) | |
| if response.status_code == 200: | |
| data = response.json() | |
| print(f"\nβ RENEWAL JOB COMPLETED") | |
| print(f" Renewed: {data.get('renewed_count', 0)} tenants") | |
| print(f" Revenue: ${data.get('total_revenue', 0):.2f}") | |
| print(f" Partner Commissions: ${data.get('total_commission', 0):.2f}") | |
| else: | |
| print(f"\nβ ERROR: {response.status_code}") | |
| print(f" Response: {response.text}") | |
| sys.exit(1) | |
| except httpx.ConnectError: | |
| print("\nβ ERROR: Cannot connect to API server") | |
| print(" Make sure the backend is running on http://localhost:8000") | |
| sys.exit(1) | |
| except Exception as e: | |
| print(f"\nβ UNEXPECTED ERROR: {e}") | |
| sys.exit(1) | |
| print(f"\n{'='*80}") | |
| print(f"π CRON JOB FINISHED: {datetime.utcnow().isoformat()}") | |
| print(f"{'='*80}\n") | |
| if __name__ == "__main__": | |
| asyncio.run(trigger_renewal_job()) | |