Skip to content

Documentation Guide on CronJobs (Nitro Tasks) #964

Open
@shoooe

Description

@shoooe

📋 Explain your issue

Reference Discord conversation: https://discord.com/channels/722131463138705510/1310190736670457856/1310190736670457856

I was able to make background jobs/tasks work in Solid Start via the following method.

  1. Add this in app.config.ts
{
    // ...
    experimental: {
      tasks: true,
    },
    scheduledTasks: {
      "* * * * *": ["cron"],
    },
}
  1. Install nitro (this is only used for defineTask below and can probably be removed if vinxi re-export those types):
pnpm add nitropack
  1. Create a file in tasks/cron.ts (notice this is NOT src/tasks) with the Nitro task definition:
import { defineTask } from "nitropack/runtime";

export default defineTask({
  meta: {
    name: "cron-name",
    description: "Run cron job",
  },
  run() {
    console.log("Running job...");
    return { result: "Success" };
  },
});

As per Nitro documentation this is only supported in dev, node-server, bun and deno-server presets.

I was asked to open a ticket here to possibly document this. HTH

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomershelp wantedLooking for assistance on this issueplannedFeatures or content that are planned but not yet in progress.solidstartRelated to SolidStart

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions