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 built a tool that shows what a contract could cost you before signing User Avatar 111 comments The coordination tax: six years watching a one-day feature take four months User Avatar 73 comments My users are making my product better without knowing it. Here's how I designed that. User Avatar 63 comments A simple LinkedIn prospecting trick that improved our lead quality User Avatar 41 comments I changed AIagent2 from dashboard-first to chat-first. Does this feel clearer? User Avatar 39 comments Why I built a SaaS for online front-end projects that need more than a playground User Avatar 14 comments