Cron jobs allow you to schedule tasks at specific intervals. Since the Vercel platform is event-driven, therefore not maintaining a running server, we recommend using a third-party service to schedule these tasks.
For example, let's say you want to hit a Serverless Function every 15 minutes. You can use any of the providers below to periodically hit your endpoint. If you need to execute a long job (greater than 30 seconds), you might consider breaking down the function into smaller pieces and using a queue (e.g. AWS SQS). This will allow you to track the state of the background job and potentially parallelize your task.
For example, with GitHub Actions you can define a new workflow .github/workflows/cron.yaml
to run a cron every 15 minutes.
name: 15-minute-cron on: schedule: - cron: '*/15 * * * *' jobs: cron: runs-on: ubuntu-latest steps: - name: Call our API route run: | curl --request POST \ --url 'https://yoursite.com/api/cron' \ --header 'Authorization: Bearer ${{ secrets.YOUR_API_KEY }}'
Providers
Related
For more information on what to do next, we recommend the following articles: