In SuperDir, there are three cron jobs, and they are:
update-launches.ts
Channels are initially in SCHEDULED status with a programmed launch date.
At 8:00 AM UTC on the launch day, the status changes to ONGOING.
At 8:00 AM UTC the next day, the status changes to LAUNCHED.
Calculate the 3 most popular projects launched yesterday.
send-ongoing-reminders.ts
At 8:30 AM UTC on the launch day, Send email reminders to users about their ongoing launches.
send-winner-notifications.ts
At 9:00 AM UTC on the launch day, Send email notifications to the winners of the day.
No matter what kind of directory site you are, update-launches.ts is a must (unless you want to manually audit and update the status directly in the database), and send-ongoing-reminders.ts and send-winner-notifications.ts are required for a directory site like Product Hunter.
The schedule time is configurable and you can modify it as needed, we will introduce it below.
Add the following environment variables to the .env file:
.env
# This is the API key of your cron job. You can generate one using `openssl rand -hex 32` or use a complex random string.CRON_API_KEY=# [only required if you're using Vercel cron jobs, otherwise you don't need to set it. The content of this value is the same as `CRON_API_KEY`.]#CRON_SECRET=
Recommended to uses FastCron to trigger cron jobs on a schedule. However, you can replace this setup with the background job service of your choosing, such as Vercel or cron-job.
To trigger a cron job, Vercel makes an HTTP GET request to your project's production deployment URL, using the path provided in your project's vercel.json file. For example, Vercel might make a request to:
https://*.vercel.app/api/cron/update-launches
Triggering functions manually
Should you need to trigger a cron job manually, you can either do so in the Vercel dashboard or just hit the endpoint with a standard HTTP request. For example:
Terminal
curl -X GET http://localhost:3000/api/cron/update-launches