Skip to content
AGNT

Backend · Core modules

Scheduler.

APScheduler runs inside the main backend process with a Redis-backed leader lock so only one worker acts on each job. The canonical list lives in agnt-backend/app/core/scheduler.py. Below is every job that ships in the current code.

How it runs

The scheduler is started in the FastAPI lifespan hook. Every job is registered via scheduler.add_job(fn, trigger, id=..., replace_existing=True), which means the process can be restarted safely without orphaned duplicates.

pythonapp/core/scheduler.py (abbreviated)
scheduler = AsyncIOScheduler()
scheduler.add_job(
    booking_reminders,
    IntervalTrigger(hours=1),
    id="booking_reminders",
    replace_existing=True,
)
# ... 39 more jobs
scheduler.start()

Timezone

Business-hour jobs use WITA (Central Indonesia Time, UTC+8) so that nightly and daily jobs fire at sensible Bali-local hours regardless of where the container actually runs. Pure interval jobs are timezone-agnostic.

All 39 jobs

Job IDSchedulePurpose
booking_remindersinterval · 1hSend upcoming-booking reminders to users.
re_engagementcron · Mon 10:00 WITAWeekly re-engagement nudge to lapsed users.
venue_daily_summarycron · 22:00 WITA dailyEvening ops summary for every venue owner.
monthly_invoicecron · 1st of month 09:00 WITAGenerate monthly subscription invoices.
retry_failed_sendsinterval · 60sRetry outbound messages in the send queue.
b2b_session_cleanupcron · 03:00 WITA dailyPurge expired B2B onboarding sessions.
deliver_remindersinterval · 5mDeliver due reminders via the channel sender.
retry_pending_feesinterval · 30mRetry Stripe fee collections that failed.
reap_stale_envelopesinterval · 15mMark PENDING envelopes past TTL as EXPIRED.
sweep_orphaned_responsesinterval · 30mClose out venue responses with no matching booking.
auto_confirm_stale_bookingsinterval · 1hAuto-confirm bookings venues forgot to accept.
purge_deleted_userscron · 04:00 WITA dailyHard-delete users past the retention window.
mark_completed_bookingsinterval · 1hTransition past-slot bookings to COMPLETED.
reconcile_subscription_statecron · 05:00 WITA dailyReconcile local subscription rows with Stripe state.
reconcile_fee_statusinterval · 30mReconcile fee collection statuses against the ledger.
recover_stuck_bookingsinterval · 15mUnstick bookings caught between A2A states.
cancel_orphaned_bookingsinterval · 30mCancel bookings whose envelope has been abandoned.
retry_dispatch_failedinterval · 30mRe-dispatch envelopes stuck in DISPATCH_FAILED.
expire_stale_referralscron · 06:00 WITA dailyExpire unredeemed referral codes past their TTL.
mark_abandoned_b2b_sessionscron · 03:30 WITA dailyMark half-finished B2B onboarding flows as abandoned.
reconcile_venue_compound_statecron · 04:00 WITA dailyReconcile venue compound state (is_active, is_claimed, etc).
check_price_watchersinterval · 6hRefresh price watchers on Shopee/Tokopedia/Lazada products.
daily_nutrition_summarycron · 21:00 WITA dailySend users their calorie diary summary.
light_dreamingcron · 02:00 WITA dailyLightweight nightly reflection over recent interactions.
deep_dreamingcron · Mon 04:00 WITAWeekly deep reflection producing new agent insights.
dlq_cleanupcron · 02:15 WITA dailyTrim the dead-letter queue of processed failures.
dlq_weekly_reportcron · Mon 06:00 WITAWeekly DLQ health report to the alerts channel.
faq_compilationcron · Sun 03:00 WITACluster support conversations into draft FAQ entries.
memory_evictioncron · 03:30 WITA dailyEvict stale user memory entries past the keep window.
reset_api_key_queries_todaycron · 08:00 WITA (00:00 UTC)Reset the per-API-key daily query counter.
charge_unbilled_usagecron · 05:00 WITA dailyBatch metered ApiKeyUsageEvent rows to Stripe.
drain_webhook_retriesinterval · 2mRetry failed outbound webhook deliveries.
prune_error_logscron · 05:30 WITA dailyDelete ErrorLog rows past the retention window.
platform_health_monitorinterval · 15mRun platform health checks and emit alerts on regression.
rating_promptinterval · 1hPrompt users to rate recent bookings.
spend_digestcron · 09:00 WITA dailySend daily user-spend digest.
rotate_delta_logcron · Sun 04:30 WITARotate the fleet delta log.
faq_extractioncron · Sun 23:59 WITAExtract FAQ candidates from the week's conversations.
rebuild_entity_graphinterval · 1hRebuild derived edges in the knowledge graph.

Inspecting running jobs

The /admin/scheduler endpoint (protected by INTERNAL_API_TOKEN) returns the current job registry with next run times. Use it to verify a deploy didn't silently drop a job.

bash
curl -H "X-Internal-Token: $INTERNAL_API_TOKEN" \
  https://api.agntdot.com/admin/scheduler

Nightly heavy work

A few jobs under cron/ are too big to live in scheduler.py directly. They are still registered as scheduler jobs but their implementation lives in dedicated files:

  • cron/dreaming.py— light + deep dreaming reflections
  • cron/graph_builder.py— knowledge graph rebuild
  • cron/faq_compile.py— weekly FAQ clustering
  • cron/wiki_reconcile.py— fleet wiki reconciliation

Related