iconSuperDir

Cron Launches

Configure cron launches to send emails and update launches.

Overview

In SuperDir, there are three cron jobs, and they are:

  1. 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.
  1. send-ongoing-reminders.ts
  • At 8:30 AM UTC on the launch day, Send email reminders to users about their ongoing launches.
  1. 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.

Configuration

Set Environment variables

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=

Add cron jobs to Jobs provider platform

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.

FastCron

The free version of FastCron has 5 scheduled jobs, and support retries. It's recommended to use.

Create a FastCron account and add three cron jobs, At least set

  • URL to call

https://your-website.com/api/cron/update-launcheshttps://your-website.com/api/cron/send-ongoing-remindershttps://your-website.com/api/cron/send-winner-notifications

  • When to call

set schedule time.

  • Send Http request fields:

set to Authorization: Bearer {CRON_API_KEY} , replace {CRON_API_KEY} with your value.

FastCron FastCron

Cron-job

Similar to FastCron, but with no support for retries.

Vercel Cron Jobs

The free version of Vercel Cron Jobs has only 2 scheduled jobs, and does not support retries.

  • Scheduling functions

You can schedule it by amending the vercel.json file in the root directory of your codebase.

{
  "crons": [
    {
      "path": "/api/cron/update-launches",
      "schedule": "0 8 * * *"
    },
    {
      "path": "/api/cron/send-ongoing-reminders",
      "schedule": "30 8 * * *"
    },
    {
      "path": "/api/cron/send-winner-notifications",
      "schedule": "0 9 * * *"
    }
  ]
}
  • How Vercel triggers cron jobs

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

On this page