From 553820035c1d73c8d14440cd5bb261cdea3806ea Mon Sep 17 00:00:00 2001 From: harshagarwalnyu Date: Mon, 1 Jun 2026 16:41:01 +0400 Subject: [PATCH 1/2] docs(solidstart): add cron jobs guide using Nitro Tasks API Documents how to set up scheduled background tasks in SolidStart using Nitro's Tasks API. Covers configuration in app.config.ts, task file structure in tasks/ directory, and manual triggering via the Nitro task endpoint. Closes #964 --- .../solid-start/(2)guides/(4)cron-jobs.mdx | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/routes/solid-start/(2)guides/(4)cron-jobs.mdx diff --git a/src/routes/solid-start/(2)guides/(4)cron-jobs.mdx b/src/routes/solid-start/(2)guides/(4)cron-jobs.mdx new file mode 100644 index 000000000..961901ccd --- /dev/null +++ b/src/routes/solid-start/(2)guides/(4)cron-jobs.mdx @@ -0,0 +1,86 @@ +--- +title: Cron jobs +use_cases: >- + background tasks, scheduled jobs, periodic jobs, cron, automation +tags: + - cron + - nitro + - tasks + - solidstart +version: "1.0" +description: >- + Schedule background tasks in SolidStart using Nitro's Tasks API for periodic + jobs and automated server-side operations. +--- + +SolidStart supports scheduled background tasks through [Nitro's Tasks API](https://nitro.build/guide/tasks). +Tasks run on the server and are not exposed to the client. + +:::note +Scheduled tasks are only supported in the `dev`, `node-server`, `bun`, and `deno-server` Nitro presets. +::: + +## Configuration + +Enable the tasks feature in `app.config.ts`: + +```ts title="app.config.ts" +import { defineConfig } from "@solidjs/start/config"; + +export default defineConfig({ + server: { + experimental: { + tasks: true, + }, + scheduledTasks: { + "* * * * *": ["cron"], // run every minute + }, + }, +}); +``` + +The `scheduledTasks` object maps [cron expressions](https://crontab.guru/) to arrays of task names to run on that schedule. + +## Creating a task + +Create your task file inside the `tasks/` directory at the project root (not inside `src/`): + +```ts title="tasks/cron.ts" +import { defineTask } from "nitropack/runtime"; + +export default defineTask({ + meta: { + name: "cron", + description: "Scheduled background job", + }, + run() { + console.log("Running scheduled job..."); + // put your server-side logic here + return { result: "Success" }; + }, +}); +``` + +The task name in `meta.name` must match the name used in `scheduledTasks` in `app.config.ts`. + +:::note +`nitropack` is a transitive dependency of SolidStart. If TypeScript cannot resolve the +import, add `nitropack` as an explicit dev dependency: + +```bash +npm install -D nitropack +# or +pnpm add -D nitropack +``` + +::: + +## Running tasks on demand + +You can trigger a task manually by calling the Nitro task endpoint during development: + +``` +/_nitro/tasks/cron +``` + +This is useful for testing your task logic without waiting for the scheduled time. From 0a0bd4f074eb6a52b6e4e62d9a029abf2c174749 Mon Sep 17 00:00:00 2001 From: harshagarwalnyu Date: Mon, 1 Jun 2026 16:49:38 +0400 Subject: [PATCH 2/2] docs: address copilot review on cron jobs guide - Add caution block warning that /_nitro/tasks/* is publicly accessible in production (node-server, bun, deno-server) and should be protected - Add curl example with explicit GET method for task triggering --- src/routes/solid-start/(2)guides/(4)cron-jobs.mdx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/routes/solid-start/(2)guides/(4)cron-jobs.mdx b/src/routes/solid-start/(2)guides/(4)cron-jobs.mdx index 961901ccd..57d72df86 100644 --- a/src/routes/solid-start/(2)guides/(4)cron-jobs.mdx +++ b/src/routes/solid-start/(2)guides/(4)cron-jobs.mdx @@ -77,10 +77,17 @@ pnpm add -D nitropack ## Running tasks on demand -You can trigger a task manually by calling the Nitro task endpoint during development: +You can trigger a task manually via the Nitro task endpoint during development using a `GET` request: -``` -/_nitro/tasks/cron +```sh +curl http://localhost:3000/_nitro/tasks/cron ``` This is useful for testing your task logic without waiting for the scheduled time. + +:::caution +The `/_nitro/tasks/*` endpoint executes server-side code on demand. In production deployments +(node-server, bun, deno-server), this endpoint is publicly reachable by default. +Protect it behind authentication, IP allowlisting, or route-level middleware before +deploying to a public environment. +:::