from app.workers.celery_app import celery_app from datetime import datetime, timezone import logging logger = logging.getLogger(__name__) @celery_app.task(name="app.workers.affiliate_tasks.check_monthly_targets") def check_monthly_targets(): """ Check affiliate monthly targets and auto-promote to employed status. Runs daily at midnight. Target: 10 deals/month = automatic employment offer. """ logger.info("Checking affiliate monthly targets for auto-employment...") # Implementation: Query all active affiliates # Check current_month_deals >= 10 # Update status to EMPLOYED # Send congratulations notification via WhatsApp/Email # Trigger employment offer generation @celery_app.task(name="app.workers.affiliate_tasks.calculate_monthly_commissions") def calculate_monthly_commissions(): """ Calculate and finalize monthly commissions for all affiliates. Runs on the 1st of each month. """ logger.info("Calculating monthly commissions...") # Implementation: Aggregate all confirmed deals per affiliate # Calculate total commissions + bonuses # Create AffiliatePerformance records # Reset current_month_deals counters # Send payment summary to affiliates @celery_app.task(name="app.workers.affiliate_tasks.send_affiliate_weekly_report") def send_affiliate_weekly_report(): """ Send weekly performance report to all active affiliates. Runs every Sunday at 9 AM Riyadh time. """ logger.info("Sending weekly reports to affiliates...") # Implementation: Compile weekly stats per affiliate # Leads generated, calls made, deals closed # Commission earned this week/month # Ranking among peers # Motivational message + tips # Send via WhatsApp @celery_app.task(name="app.workers.affiliate_tasks.ai_lead_generation_scan") def ai_lead_generation_scan(): """ AI agent scans for new potential leads from various sources. Runs every 6 hours. """ logger.info("AI lead generation scan initiated...") # Implementation: Scrape Google Maps by industry/city # Search LinkedIn for decision makers # Check business directories # Score and qualify leads # Add to outreach queue @celery_app.task(name="app.workers.affiliate_tasks.ai_outreach_followup") def ai_outreach_followup(): """ AI agent follows up with leads in active conversations. Runs every 30 minutes. """ logger.info("AI outreach follow-up check...") # Implementation: Check active conversations # Send follow-ups for conversations with no response > 24h # Escalate hot leads to human sales reps # Update sentiment and interest scores @celery_app.task(name="app.workers.affiliate_tasks.process_auto_bookings") def process_auto_bookings(): """ Process and confirm auto-booked meetings. Runs every 15 minutes. """ logger.info("Processing auto-bookings...") # Implementation: Check new booking requests # Send calendar invites to sales reps # Send confirmation to clients via WhatsApp/Email # Update booking status