Strapi cron jobs for scheduled tasks

Strapi's built-in cron feature runs custom functions at set times, configured in the server settings with optional task files. This page covers how to set it up, the timezone and multi-instance risks to plan for, and what to confirm before relying on it in production.

On this page

When Strapi cron jobs fit scheduled work inside the CMS

A team that needs content or integration work to run on a timetable, such as clearing expired drafts or sending a weekly content digest, can run that work inside Strapi using the built-in cron feature. Strapi cron jobs schedule custom functions at specific times using node-schedule, and they are activated through the server configuration with optional task files. The question to answer first is whether the job only touches Strapi data and logic. If it reads or writes entries, media or users through the Strapi application code and does not need to reach far outside the CMS, an in-process schedule keeps the logic close to the content model, permissions and lifecycle hooks that already exist in the project.

Running inside Strapi fits best when the job is small, deterministic and tied to the content model: unpublishing entries after a date field passes, archiving stale drafts, recalculating a derived field, or triggering a notification that the CMS already knows how to produce. It also suits teams with a single Strapi instance and no separate job platform, because there is one codebase, one deployment and one set of logs to review. Confirm in the official cron documentation how task files are registered and how the server configuration enables the feature in your Strapi version before you commit to this pattern.

An external scheduler such as a Kubernetes CronJob, a workflow engine or an orchestration tool fits better when the work spans several systems, needs retries with independent monitoring, runs long batch processing that should not share the CMS process, or must run on a schedule owned by another team. It is also the safer choice when the job must run exactly once across many replicas and your team has not yet designed for that. Ask who will be paged when the job fails, how missed runs are detected, and whether the schedule must survive a CMS redeploy before choosing. Write the decision down, because moving a job out of Strapi later is harder than keeping it there from the start.

Which cron configuration approach fits your task

Inline scheduling means the cron expression and the function it runs are declared directly in the server configuration, with the cron feature enabled there. It is the smallest option: one file, no extra modules, and the schedule is visible next to the rest of the server setup. The trade-off is that the function body grows quickly, and it becomes harder to read, review and test once the job does real work.

  • Maintainability: Good for one or two short schedules. Each new job adds more logic to a file that also controls the server, so changes to the schedule and the job share a review.
  • Testability: Harder to unit test, because the function is defined inside configuration. Teams often move the logic into a service and call it from a one-line entry.
  • Secrets and database access: The configuration runs inside the Strapi process, so the job can use the Strapi instance and its database access directly. Keep credentials in environment variables, not literal values in the file.
  • Duplicate runs: Every instance that loads this configuration registers the same schedule, so a multi-instance deployment needs its own guard.
  • Best fit: Short, low-risk housekeeping that a single developer can explain in a few lines.

Before you choose this route, confirm the scheduling behavior and timezone handling against the Strapi cron docs for your version.

Enabling and testing a Strapi cron job

This sequence takes a Strapi project from cron switched off to a scheduled function that runs at a set time and logs when it fires. Each step ends with a check so the team can confirm the job is wired correctly before it touches real content.

  1. Confirm the Strapi project and environment

    The developer confirms which Strapi project, Node.js version and database the schedule will run against, and that the work happens in a local or development instance rather than staging or production. Check the Node.js version against the Active or Maintenance LTS list in the Strapi installation requirements before going further. Done means the team can name the target environment in writing and the project starts cleanly with its current configuration.

  2. Enable cron in the server configuration

    Open the server configuration file in the project's config folder and turn on the cron feature, using the key documented in the Strapi cron docs. Keep the setting in the development configuration so it does not spread to other environments by accident. Restart Strapi and confirm it still boots without errors in the terminal. Done means the server starts with cron enabled and no configuration warnings.

  3. Create the task file

    Add a task file in the project's configuration folder that exports the schedule and the function to run, following the structure shown in the Strapi cron docs. Give the file a name that describes the job, such as a daily report or a cleanup, so later maintainers can find it. Keep the first version to a function that only writes a log line. Done means the file is saved, the project restarts, and the task file is loaded without a parse or import error.

  4. Set the schedule and timezone

    Write the cron expression for a time close to the test window and set the timezone explicitly in the task definition instead of relying on the host machine's default. Note the timezone in the file comment so the next person knows which clock the schedule follows. Use a schedule that fires within a short, known window during the test so the result is easy to observe. Done means the expression and timezone are written down and the team agrees on the expected firing time.

  5. Make the test task non-destructive

    Before the schedule is active, make sure the function only reads data or writes to a log or a dedicated test record. Do not let the first run update, publish or delete entries, send email, or call external systems. Mark the test in a code comment so it is removed or replaced before promotion. Done means a reviewer has read the function and agrees that a wrong run would cause no lasting change.

  6. Verify the first run and the startup behavior

    Start Strapi and watch the log output. Confirm the job does not fire immediately on startup unless the schedule was meant to do that, and then confirm it fires at the expected time in the expected timezone. Repeat the check after a restart to see whether the job fires again or resumes on its own schedule. Done means the team has a log entry with the expected timestamp and a written note of any unexpected startup run that needs fixing.

  7. Record findings before wider rollout

    Write down the expression, timezone, log output, startup behavior and any surprises, then list what must change before the job runs in shared or production environments. Include a question for the team about how multiple instances will share the schedule, since that affects where the job is allowed to run. Done means a short written record exists that a second engineer can follow, and the team has decided whether the job moves to the next environment.

How timezones change when a scheduled task fires

A scheduled task fires at the time the server and its configuration interpret, not at the time your editors have in mind. Strapi cron jobs are triggered by node-schedule, so the effective timezone is whatever the Node.js process, its container and the schedule definition resolve to at runtime. A host set to one timezone, a container image defaulting to UTC and a team working in another zone can all disagree about when a job should run. Write down which timezone each layer uses before you set any time in a task, and make the value explicit in the schedule rather than relying on a default you never checked.

Before production, confirm how your chosen schedule library handles timezone names, offsets and daylight saving transitions. Read the node-schedule documentation for the version your project pins, and check whether a rule written in local time is evaluated against the host clock or converted to a fixed zone. Some setups run a job twice or skip it during a clock change, and the behavior can differ between a recurring rule and a one-off date. Ask the library maintainers or your own engineers to confirm this in writing for your exact version instead of assuming it from general cron knowledge. The Strapi cron documentation is the starting point for how tasks are registered in your project.

Test across a real clock change on a staging instance with the same container image, host settings and environment variables as production. Set a task to fire shortly before and after the transition, record the actual execution times in your logs and compare them with what the team expected. Repeat the test for any job that touches publishing, expiry or notifications, because a missed or doubled run can have editorial or compliance consequences. Keep the timezone settings under version control with the rest of the deployment configuration, so a later change to a base image or host does not silently move every schedule.

What to watch when several Strapi instances run the same schedule

Strapi cron jobs run inside each server process, so every instance that boots with the same schedule will try to run it. The cards below cover the main failure modes and the controls that keep one scheduled run from becoming many, and each one names what to confirm for your deployment.

Every instance runs the job

Cron jobs are registered in the server configuration, so each Strapi process that loads that configuration registers the same schedule. Two replicas behind a load balancer will both fire at the configured time unless something stops the second run. Before go-live, check how many processes start the server, including container replicas, cluster workers and any admin-only or preview instances, and confirm which of them load the cron configuration.

Strapi cron docs

Duplicate emails and external writes

A task that sends a newsletter, posts to a CRM or calls a payment API becomes a duplicate action when it runs once per instance. The side effect is what multiplies, not the schedule itself. Identify every task that sends messages, calls third-party APIs or creates records outside Strapi, and decide whether each one can be safely repeated before you rely on the default behavior.

Single designated worker

One common control is to enable scheduled tasks on one designated instance only, controlled by an environment variable or a separate worker deployment, and to leave the schedule off elsewhere. This is simple to reason about but creates a single point of failure for scheduled work. Confirm who restarts that worker if it stops, and whether alerts fire when the expected run does not happen.

Database locking for runs

A lock stored in the shared database, such as a row with a run ID and an expiry time, lets each instance attempt to claim a run and skip it if another instance already holds the claim. The lock must be acquired atomically and released or expired after a crash. Test the claim with two instances started at the same second, and confirm that the database engine you chose (PostgreSQL, MySQL, MariaDB or SQLite) handles the locking statement the way your design assumes.

Idempotent task design

Write each task so that running it twice for the same period produces the same result. Store a key for each logical run, such as the date and task name, and check it before sending or writing. This protects against overlapping runs, retries after a timeout and manual reruns, and it is the control that still works when the locking layer fails. Ask for the rerun procedure in writing before launch.

Content race conditions and rolling deploys

A job that edits entries can collide with editors or with a second run, and a rolling deploy can leave old and new code running the same schedule at once with different logic. Keep scheduled writes narrow, avoid long transactions, and use a version or deploy marker that the task checks before it acts. During deploys, confirm whether the platform stops old instances before starting new ones, and whether scheduled runs are paused during the window.

Questions buyers ask about Strapi cron jobs

What does a Strapi cron job setup cost, and what drives the effort?

The built-in cron feature itself is part of Strapi, so the main cost is the engineering time to design, write and test the scheduled tasks. Effort rises with the number of jobs, how much each job touches content or external systems, how failures must be reported, and how many environments and instances must behave the same way. Cost is one-time for the initial build and recurs only when schedules change or the job logic needs maintenance after Strapi upgrades. Ask any partner for a quote that lists each job, its inputs and outputs, its failure handling, and the environments it covers. DeployOpen provides written, fixed-scope quotes based on that scope.

How long does a typical Strapi scheduled task setup take?

Duration depends on the number and complexity of the jobs, not on the cron feature, which is switched on through the server configuration. A single job that only reads and writes Strapi content can be small, while jobs that call third-party APIs, handle retries, or need monitoring take longer to design and test. Schedule rules, timezone decisions and multi-instance behavior also add review time. Confirm the timeline against the written scope, and ask for each job to be listed with its dependencies so the estimate is traceable.

What must our team provide before a partner can build Strapi cron jobs?

The team needs to provide a list of the tasks that must run, the schedule each one needs, and the business rule behind it. Engineers should share the Strapi version in use, the database and hosting setup, and how many instances run in each environment. Access to a staging environment is needed for testing, along with a named owner for alerts and job failures. Decisions on timezone, such as whether schedules follow UTC or a local office time, should be made by the business owner before build starts.

Can an in-house Strapi developer set up cron jobs alone?

Yes, a developer who knows Strapi and Node.js can enable the cron feature in the server configuration and write task files for straightforward schedules. The work becomes harder when jobs must be idempotent, when several instances run the same code, or when failures must reach an operations team. Your own team is usually the right owner for the business logic, since it knows the rules. A partner adds value when you need an outside review of scheduling behavior, a test plan, or help running the jobs safely across environments. Decide based on the number of jobs and your team's spare capacity.

How does Strapi cron scheduling work with several instances?

The built-in cron feature runs scheduled functions inside each Strapi process that loads the server configuration, so every instance with the feature enabled can fire the same job at the same time. Without coordination, a job that sends email or publishes content may run more than once. Plan for this before launch by deciding which instance owns a job, making jobs idempotent, or moving the schedule to a single worker process. Test the behavior with two running instances in staging. Confirm the exact behavior with the Strapi cron documentation for your version before relying on it.

Which timezone should a Strapi scheduled task use?

Use UTC as the default for jobs that run on a server clock, and convert to local time only where a business rule requires it. Server timezone settings differ between hosts, containers and cloud regions, so a job set to run at a local time can shift when the infrastructure moves. Daylight saving changes can also cause a job to run twice or skip an hour if the schedule is written in local time. Document the chosen timezone in the task file and in your runbook, and test the schedule around a daylight saving change.

What goes wrong with Strapi scheduled tasks in production?

The most common problems are duplicate runs across instances, jobs that fail silently, and schedules that drift after an environment change. Jobs that call external services can also stall when those services are slow, which can cause overlapping runs. Upgrades can change the surrounding code the task depends on, so tasks should be included in upgrade testing. Add logging, alerting on failures, and a documented way to disable a job during an incident. Review the setup with the Strapi cron documentation for your version and confirm each behavior in your own environment.

Are Strapi cron jobs covered by DeployOpen's scope?

Yes, scheduled tasks inside a self-hosted Strapi project can be part of a fixed-scope implementation, including task design, testing, and operational notes. DeployOpen plans and builds the work inside your own infrastructure, and it does not issue compliance attestations for the result. The written scope should name each job, the instances it runs on, and the handover material your team receives. Ongoing changes to jobs can be handled through a retainer if you need continued support.

How a scheduled task moves through Strapi instances

The flow starts in the server configuration, where cron is enabled and tasks are registered, and hands off to node-schedule, which fires the task function at its configured time. When several Strapi instances run the same schedule, each one fires its own copy unless the task checks a lock or a designated worker before it writes to the database or calls an outside service. Check that decision point first, because it decides whether a task runs once or once per instance.

Each instance fires the schedule, so a lock or designated worker gates shared side effects.

How DeployOpen scopes and delivers Strapi scheduled tasks

DeployOpen treats Strapi cron jobs as part of the wider Strapi build, starting with a written list of the scheduled jobs, their timing and their side effects. We then build, test and document the schedules inside your Strapi project and your own infrastructure, and agree how they will be run and supported after handover.

How we scope

  • List each scheduled job, its purpose, the Strapi content it touches and the systems it calls.
  • Confirm the timezone each schedule must follow and how daylight saving changes are expected to behave.
  • Agree how many Strapi instances run in production and which instance is allowed to run each job.

How we build

  • Enable the cron setting in server configuration and place task definitions in the agreed task files.
  • Write each job so it can run twice safely, with logging that shows start, finish and failure for each run.
  • Test schedules in a staging environment, including a run across several instances, before production use.

How we hand over

  • Document every schedule, its timezone, owner, expected duration and the steps to disable it quickly.
  • Walk your platform and editorial teams through how to read job logs and recognize a missed or duplicated run.
  • Deliver the configuration in your repository so changes to schedules go through your normal review process.

How we support

  • Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
  • Ongoing support, upgrades and continuous testing are available as a retainer after handover.
  • Ask any partner to confirm how scheduled jobs will be re-tested when you upgrade Strapi versions.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.