4
6 Comments

[Ask IH]: How do you run cron jobs on Vercel or Netlify?

Hey Indie Hackers,

I'm curious how everyone is running corn jobs when you're deploying NextJS apps on either Vercel or Netlify.

There are very popular ways of handling this:

Have y'all seen any great ways to do something similar in the NextJS / Node ecosystem?

I'm considering SaaS and run-it-yourself open source solutions.

Thanks.

posted to Icon for group Developers
Developers
on May 12, 2020
  1. 4

    We've added a new section to the docs with cron job recommendations!

    https://vercel.com/docs/solutions/cron-jobs

  2. 2

    Lately i have been using Github Workflows to do scheduled things. I use it to trigger a daily webhook for doing nightly builds in Netlify, works like a charm and very easy to set up

    1. 1

      I like this a lot! Thanks for the idea.

  3. 1

    Following up here,

    I built Slater, a cron job service built explicitly for Next.js & Vercel. It's entirely free right now while I'm in early access. Just sign up for the waitlist on the homepage and I'll email you some info to get started.

    It's essentially cron jobs as code that I automate the endpoints with.

    You write code like this:

    // pages/api/slater/[...slater].js

    import { slater } from "[@slaterjs](/slaterjs)/next";
    const config = {
      tasks: [
        {
          name: "helloWorld",
          schedule: "0 7 * * *", // 7AM
          handler: async (event, success, failure) => {
            try {
              const results = await fetch(
                "https://jsonplaceholder.typicode.com/posts/1"
              );
              const data = await results.json();
              if (results.ok) {
                return success(data);
              } else {
                return failure(data);
              }
            } catch (err) {
              return failure(err); // sends 500
            }
          },
        },
      ],
    };
    
    export default slater(config);
    

    and when you deploy to prod on Vercel, Slater will hit the endpoint according to the cron schedule you set (UTC time).

    Check it out here: https://tryslater.com

  4. 1

    If you have a node.js backend you can use node-schedule. The jobs don't persists so you need to store them in a database if that's needed.

Trending on Indie Hackers
I'm a lawyer who launched an AI contract tool on Product Hunt today — here's what building it as a non-technical founder actually felt like User Avatar 150 comments A simple way to keep AI automations from making bad decisions User Avatar 59 comments “This contract looked normal - but could cost millions” User Avatar 54 comments Never hire an SEO Agency for your Saas Startup User Avatar 44 comments 👉 The most expensive contract mistakes don’t feel risky User Avatar 41 comments The indie maker's dilemma: 2 months in, 700 downloads, and I'm stuck User Avatar 41 comments