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
AI runs 70% of my distribution. The exact stack. User Avatar 147 comments I'm a solo founder. It took me 9 months and at least 3 stack rewrites to ship my SaaS. User Avatar 128 comments Show IH: I'm building a lead gen + CRM tool for web designers targeting local businesses without websites — starting with Spain User Avatar 79 comments I built a URL indexing SaaS in 40 days — here's the honest story User Avatar 58 comments We could see our AI bill, but not explain it — so I built AiKey User Avatar 25 comments AI coding should not turn software development into a black box User Avatar 11 comments