Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Documentation Guide on CronJobs (Nitro Tasks) #964

Open
shoooe opened this issue Nov 25, 2024 · 1 comment
Open

Documentation Guide on CronJobs (Nitro Tasks) #964

shoooe opened this issue Nov 25, 2024 · 1 comment
Labels
good first issue Good for newcomers help wanted Looking for assistance on this issue planned Features or content that are planned but not yet in progress. solidstart Related to SolidStart

Comments

@shoooe
Copy link

shoooe commented Nov 25, 2024

📋 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

@shoooe shoooe added the pending review Awaiting review by team members. label Nov 25, 2024
@atilafassina atilafassina added help wanted Looking for assistance on this issue planned Features or content that are planned but not yet in progress. and removed pending review Awaiting review by team members. labels Dec 20, 2024
@atilafassina
Copy link
Member

This is a pretty awesome feature that Nitro brings in and I had no idea about until you pointed it out on Discord

I think it deserves a section in the SolidStart Guides

  • Add in SolidStart > Guides > Cron an explanation on how to create CronJobs via the Tasks API in Nitro

@atilafassina atilafassina added the good first issue Good for newcomers label Dec 20, 2024
@atilafassina atilafassina changed the title [Other]: Tasks Documentation Guide on CronJobs (Nitro Tasks) Dec 20, 2024
@atilafassina atilafassina added the solidstart Related to SolidStart label Dec 20, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
good first issue Good for newcomers help wanted Looking for assistance on this issue planned Features or content that are planned but not yet in progress. solidstart Related to SolidStart
Projects
None yet
Development

No branches or pull requests

2 participants