Skip to content
Start free

Scheduled Tasks

Open in ClaudeOpen in ChatGPT

DocSpring Enterprise has three scheduled tasks. Schedule each one to run from the same image, with the same settings as your services:

TaskCommandScheduleExample cron
Hourlyrun_as_deploy rake timers:hourlyOnce an hour15 * * * *
Dailyrun_as_deploy rake timers:dailyOnce a day0 3 * * *
Weeklyrun_as_deploy rake timers:weeklyOnce a week0 4 * * 0

Each release decides what these three run, so a release can add, change or remove a scheduled task without a change to your setup. Any time of day works for the daily and weekly tasks. If a run is still going when the next one starts, the next one exits without doing anything, so a slow run never overlaps itself. That check holds a PostgreSQL lock for the whole run, so the tasks need a direct database connection, not one through PgBouncer in transaction mode (Database connections).

What each task runs in the current release. Each step runs even if an earlier one fails, and the task exits with an error at the end if any step failed, so your platform’s alerts for failed jobs work.

Hourly:

  • Deletes API logs and webhook logs over 90 days old.
  • Records PgHero’s query statistics, for the database page in the admin dashboard.

Daily:

  • Expires submissions past the expiry their account or template sets, after emailing the account’s owner when someone shortens it.
  • Runs the data retention tasks. Each one only logs what it would delete until you turn on its setting.
  • Recounts each account’s processed submissions and the admin dashboard’s statistics.
  • Deletes expired OAuth codes and tokens, and refreshes Google Drive and Box connections before their tokens expire.
  • Removes failed background jobs over 60 days old, and PgHero statistics it no longer needs.
  • Fails PDF tools jobs that have waited for hours without running, so they stop counting toward the account’s limit of waiting jobs.

Weekly: nothing yet. Schedule it anyway, so a release can use it.

To run one step by hand, name it with ONLY, for example run_as_deploy rake timers:daily ONLY=submissions:expire_overdue_submissions.

Our deployment configs schedule all three for you:

  • Docker Compose: install-schedule.sh adds them to the server’s cron, running docker compose run --rm tasks run_as_deploy rake timers:hourly and so on.
  • Kubernetes: the Helm chart makes three CronJobs, with concurrencyPolicy: Forbid.
  • AWS ECS: the Terraform module makes three EventBridge Scheduler schedules that run a task each.
  • Convox: three timers in convox.yml, on the command service.
  • Aptible: a cron service runs them with supercronic, since Aptible has no scheduler.

On another platform, use its scheduler for containers (a cron job that runs docker run, a Nomad periodic job, a Cloud Run job with Cloud Scheduler). Give each run the same image, settings and container security settings as your worker.