nitrojs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.build
MIT License
6.23k stars 514 forks source link

Cron operations inside Nitro #1634

Open VladimirCores opened 1 year ago

VladimirCores commented 1 year ago

Describe the feature

As a developer I would like to run cron operation, they start automatically on engine start (with their own state restored from cache).

Additional information

pi0 commented 1 year ago

Thanks for the suggestion. We are planning to support nitro tasks which can be a good fit for from support. I will escalate your issue to that as soon as could write RFC/POC.

kingtimm commented 1 year ago

This sounds amazing. I am migrating some cron jobs from vercel to supabase. Is the thought with Nitro Tasks that they would be converted through presets for different providers - or default to something like node-cron?

pi0 commented 1 year ago

Certainly provider agnostic :) (we can use nitro plugins to hook into node-cron, etc)

productdevbook commented 1 year ago

When prerendering and using node-cron, build hangs

import cron from 'node-cron'

export default defineNitroPlugin(async () => {
  startCron()
})

function startCron() {
  cron.schedule('0 4 * * *', async () => {
    console.warn('Running scheduled task')
  })
  console.warn('Cron started')
}