# Background jobs for the Docker Compose deployment.
#
# These mirror helm/sim/values.yaml `cronjobs.jobs` one-for-one — same paths,
# same schedules — so Compose and Kubernetes deployments behave identically.
# Keep the two in sync when adding or changing a job.
#
# Every endpoint authenticates with CRON_SECRET as a bearer token and is a GET.
# The application does its own overlap prevention (advisory locks / SKIP LOCKED),
# so the scheduler only has to fire on time.
#
# SIM_URL and CRON_SECRET are read from the container environment, which
# supercronic passes through to each job's shell.

SHELL=/bin/sh

# Scheduled workflows
*/1 * * * * curl -fsS -m 60 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/schedules/execute"

# Polling triggers
*/1 * * * * curl -fsS -m 60 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/webhooks/poll/gmail"
*/1 * * * * curl -fsS -m 60 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/webhooks/poll/outlook"
*/1 * * * * curl -fsS -m 60 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/webhooks/poll/imap"
*/1 * * * * curl -fsS -m 60 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/webhooks/poll/rss"
*/1 * * * * curl -fsS -m 60 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/webhooks/poll/google-sheets"
*/1 * * * * curl -fsS -m 60 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/webhooks/poll/google-drive"
*/1 * * * * curl -fsS -m 60 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/webhooks/poll/google-calendar"
*/1 * * * * curl -fsS -m 60 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/webhooks/poll/hubspot"

# Time-based workflow resume and the transactional outbox
*/1 * * * * curl -fsS -m 60 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/resume/poll"
*/1 * * * * curl -fsS -m 60 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/webhooks/outbox/process"

# Knowledge base connector syncs
*/5 * * * * curl -fsS -m 120 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/knowledge/connectors/sync"

# Workspace event triggers
*/15 * * * * curl -fsS -m 60 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/workspace-events/poll"

# Enterprise data drains
0 * * * * curl -fsS -m 300 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/cron/run-data-drains"

# Microsoft Graph subscription renewal (Teams chat triggers expire after ~3 days)
0 */12 * * * curl -fsS -m 120 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/cron/renew-subscriptions"

# Reclaims sandbox images
30 4 * * * curl -fsS -m 300 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/cron/cleanup-sandbox-images"

# Inbox entitlement reconciliation
0 3 * * * curl -fsS -m 120 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/cron/reconcile-inbox-entitlement"

# Billing-seat reconciliation. Only meaningful with billing enabled; harmless
# otherwise, and kept so the job set matches the Helm chart exactly.
0 * * * * curl -fsS -m 120 -o /dev/null -H "Authorization: Bearer $CRON_SECRET" "$SIM_URL/api/cron/reconcile-billing-seats"
