Close

Sign up to Gadget

Introducing cron jobs and scheduled Actions

-

About

Run Javascript code to do whatever you want on a regular basis, using Gadget's new robust scheduler system.

Problem

Solution

Result

Introducing cron jobs and scheduled Actions

Mo Hashemi
November 4, 2022

Many Actions often need to be run on a regular basis without having to be told, such as sending out welcome emails or cleaning up defunct data. Traditionally, developers have used <inline-code>cron<inline-code> or similar utilities to kick off this repeating work, but with serverless platforms like Gadget, a different solution is needed.

This is why, starting today, Gadget apps have one-click access to a robust scheduler system that will run any Global Action on a regular basis. Gadget’s Global Actions are top-level units of work that can run JavaScript code to do whatever you need on a regular basis: send emails, write to the database, make API calls, etc.

To create a schedule, you add a new Scheduler Trigger to your Global Action, and then configure the schedule you want to run the Global Action on. For example, we could create a Global Action to send an email to us each week with a list of new customers:


We can then trigger this Global Action weekly using the new Scheduler Trigger, which gives you the ability to set schedules based on a variety of parameters.

Scheduling a Global Action is easy, it takes just a few clicks.

Scheduled Global Actions will run the same way as a Global Action triggered by the GraphQL API.. This means the same logs will show up in your Logger, the same transaction configuration will apply, etc. Notably, Global Actions can optionally be triggered both on a schedule and via your API, so you can still run them via the API Playground or via calls in your application.

Until next *time*!

Interested in learning more about Gadget?

Join leading agencies making the switch to Gadget and experience the difference a fullstack platform can make.

Keep reading

No items found.
Keep reading to learn about how it's built

Under the hood

At Gadget we’re big fans of Temporal, and use it to run our own internal background workflows, including our own scheduled work. It is remarkably fast and robust, and we’ve ported just about all our background workflows over to it over the past year. Under the hood, we use Temporal to run each app’s scheduled work as well.

Each schedule you create in your Gadget application is implemented using one Temporal workflow under the hood. Gadget takes care of creating, updating, and deleting the workflow’s schedule, and ensures that it runs exactly the Global Action you want at the right time. Each of these scheduled workflows is quite lightweight, so we can allow our users to create many schedules without concern, and retain good observability over all of them with Temporals built-in dashboards.

Temporal is an amazing building block for us as platform implementers, but we’ve certainly spent a lot of time learning The Temporal Way™ and how to operate it successfully. We’ve fought through a number of webpack-related (on the server!) issues, reliability and retry semantics, added a lot of observability instrumentation, and stress-tested our setup to ensure we really will run your code right on schedule. We’re glad that we can be the ones to run this complex software, and offer our customers a really simple and reliable scheduler on top.

We're on Discord, drop in and say hi!
Join Discord
Bouncing Arrow