Introducing cron jobs and scheduled Actions
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.
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*!