iachat/config/schedule.yml
Rodribm10 f6488ce2de feat(retention): foundation for customer retention metrics
Lays the data + job foundation for tracking customer interactions,
recurrence, and Pix conversion on Contact. Design decisions negotiated
with Rodrigo (see docs to come):

Rules:
- Gap of 30h from last message defines separate interactions
- Qualified interaction = >=2 customer msgs + >=2 attendant msgs,
  both with textual content (>= 2 letters)
- One-shot consultation = >=1+1 but below the qualified threshold
  (tracked as secondary KPI)
- Excludes contacts labeled `equipe_interna`
- is_recurring = interactions_count >= 2
- pix_generated_count counts all PixCharges; reservations_paid_count
  only counts those with status = paid

Surface area:
- Migration adds denormalized stats to contacts + indexes for fast filtering
- Captain::ContactStats::InteractionCalculatorService computes the stats
  for a single contact (pure, no persistence)
- Captain::Retention::RecalculateContactStatsJob persists them for one
  contact (idempotent)
- Captain::Retention::RecalculateAllContactStatsJob runs daily at 3am BRT,
  enqueues per-contact jobs for everyone active in the last 120 days
- Event-driven refresh: CaptainListener#conversation_resolved enqueues
  recalc; Captain::PixCharge after_create/after_update enqueues recalc
  on status change

No UI yet — that's the next layer.
2026-04-22 09:50:23 -03:00

162 lines
5.3 KiB
YAML

# https://github.com/ondrejbartas/sidekiq-cron
# use https://crontab.guru/ to validate
# validations for this file exist in /spec/configs/schedule_spec.rb
# executed At 12:00 on every day-of-month.
internal_check_new_versions_job:
cron: '0 12 */1 * *'
class: 'Internal::CheckNewVersionsJob'
queue: scheduled_jobs
# # executed At every 5th minute..
trigger_scheduled_items_job:
cron: '*/5 * * * *'
class: 'TriggerScheduledItemsJob'
queue: scheduled_jobs
# Fallback pra draws da roleta revelados cujo callback do front falhou.
# Executa a cada 5 minutos.
captain_roleta_notify_revealed_scheduler_job:
cron: '*/5 * * * *'
class: 'Captain::Roleta::NotifyRevealedSchedulerJob'
queue: scheduled_jobs
# Re-engajamento de clientes recorrentes que sumiram há 60+ dias.
# Roda de hora em hora das 13h às 20h UTC (10h às 17h BRT).
# O job verifica internamente se está em horário comercial BRT + dia útil.
captain_retention_churn_outreach_scheduler_job:
cron: '5 13-20 * * 1-5'
class: 'Captain::Retention::ChurnOutreachSchedulerJob'
queue: scheduled_jobs
# Recalcula stats de retenção (interações, Pix, reservas, recorrência) de
# todos os contatos ativos nos últimos 120 dias. Roda diariamente às 3am BRT
# (6am UTC) — fora do horário comercial pra não competir com atendimento.
captain_retention_recalculate_all_contact_stats_job:
cron: '0 6 * * *'
class: 'Captain::Retention::RecalculateAllContactStatsJob'
queue: scheduled_jobs
# executed every minute.
trigger_scheduled_messages_job:
cron: '* * * * *'
class: 'ScheduledMessages::TriggerScheduledMessagesJob'
queue: scheduled_jobs
# executed At every minute..
trigger_imap_email_inboxes_job:
cron: '*/1 * * * *'
class: 'Inboxes::FetchImapEmailInboxesJob'
queue: scheduled_jobs
# executed daily at 2230 UTC
# which is our lowest traffic time
remove_stale_contact_inboxes_job.rb:
cron: '30 22 * * *'
class: 'Internal::RemoveStaleContactInboxesJob'
queue: scheduled_jobs
# executed daily at 2230 UTC
# which is our lowest traffic time
remove_stale_redis_keys_job.rb:
cron: '30 22 * * *'
class: 'Internal::RemoveStaleRedisKeysJob'
queue: scheduled_jobs
# DISABLED: investigating if this job is the source of orphan conversations
# #executed daily at 0430 UTC
# # which will be IST 10:00 AM
# process_stale_contacts_job:
# cron: '30 04 * * *'
# class: 'Internal::ProcessStaleContactsJob'
# queue: housekeeping
# executed daily at 0100 UTC
# to delete accounts marked for deletion
delete_accounts_job:
cron: '0 1 * * *'
class: 'Internal::DeleteAccountsJob'
queue: scheduled_jobs
# executed every 15 minutes
# to assign unassigned conversations for all inboxes
bulk_auto_assignment_job:
cron: '*/15 * * * *'
class: 'Inboxes::BulkAutoAssignmentJob'
queue: scheduled_jobs
# executed every 10 minutes
# proactively checks pending PIX charges (Inter) while txid is still valid
captain_proactive_pix_polling_job:
cron: '*/10 * * * *'
class: 'Captain::Payments::ProactivePixPollingSchedulerJob'
queue: scheduled_jobs
# executed every 30 minutes for assignment_v2
periodic_assignment_job:
cron: '*/30 * * * *'
class: 'AutoAssignment::PeriodicAssignmentJob'
queue: scheduled_jobs
# executed daily at 2230 UTC
# removes old notifications (>1 month) and trims to 300 per user
remove_old_notification_job:
cron: '30 22 * * *'
class: 'Notification::RemoveOldNotificationJob'
queue: purgable
# executed every 12 hours
# to remove orphan conversations without contact
remove_orphan_conversations_job:
cron: '0 */12 * * *'
class: 'Internal::RemoveOrphanConversationsJob'
queue: housekeeping
# executed every 5 minutes
# scans reservations and sends configured notification templates (pre/post arrival)
captain_notification_scanner_job:
cron: '*/5 * * * *'
class: 'Captain::Notifications::NotificationScannerJob'
queue: scheduled_jobs
# executed every hour
# keeps landing page promotions and Captain knowledge in sync (including expired promotions cleanup)
landing_hosts_promotion_sync_scheduler_job:
cron: '0 * * * *'
class: 'LandingHosts::PromotionSyncSchedulerJob'
queue: scheduled_jobs
# Sunday at 04:00 UTC (01:00 BRT)
# Generates weekly LLM insights for every account + every captain unit.
# Each account gets a global insight (all conversations) plus one per unit.
captain_weekly_insights_job:
cron: '0 4 * * 0'
class: 'Captain::Reports::WeeklyInsightsJob'
queue: scheduled_jobs
# Monday at 11:00 UTC (08:00 BRT)
# Aggregates last week's insights and delivers the CEO Digest to Mattermost.
# Requires per-account config in account.custom_attributes.ceo_digest
# or fallback ENV CEO_DIGEST_MATTERMOST_WEBHOOK_URL.
captain_ceo_digest_job:
cron: '0 11 * * 1'
class: 'Captain::Reports::CeoDigestJob'
queue: scheduled_jobs
# every 10 minutes - detects silent conversations for memory extraction
captain_contact_memory_silence_detector_job:
cron: '*/10 * * * *'
class: 'Captain::ContactMemories::SilenceDetectorJob'
queue: scheduled_jobs
# weekly - Sundays at 03:00 UTC - TTL aging + LRU cap of contact memories
captain_contact_memory_aging_job:
cron: '0 3 * * 0'
class: 'Captain::ContactMemories::AgingJob'
queue: scheduled_jobs
# daily at 03:30 UTC - hard-delete soft-deleted contact memories older than 30 days (LGPD)
captain_contact_memory_hard_delete_job:
cron: '30 3 * * *'
class: 'Captain::ContactMemories::HardDeleteExpiredJob'
queue: scheduled_jobs