When building backend applications you often need to run periodic and recurring tasks. For example, to send a welcome email to everyone who signed up recently. Encore provides native support for these types of use cases using Cron Jobs. Here's how easy it is:
import "encore.dev/cron"
// Send a welcome email to everyone who signed up in the last two hours.
var _ = cron.NewJob("welcome-email", cron.JobConfig{
Title: "Send welcome emails",
Every: 2 * cron.Hour,
Endpoint: SendWelcomeEmail,
})
That's it! When this is deployed, Encore will call the SendWelcomeEmail
endpoint (not pictured) every 2 hours. There is no need to maintain any infrastructure; Encore itself takes care of the scheduling, monitoring and execution. Hooray!
What's more, Encore's Cloud Dashboard has a shiny new Cron Jobs dashboard to help you keep track of all your jobs. Check it out:
This means you can now schedule recurring tasks without worrying about:
To get started, install the latest Encore release with encore version update
and upgrade your application's dependency with go get encore.dev@latest
.
Check out the docs to learn more.
encore test -cover
(#144)encore test
mistakenly requiring Docker when the app has no database (#98)Thanks to @ValeriaVG and @wisdommatt for the contributions!
Over the coming weeks we’ll be adding several powerful features to help you build your backend. Soon we’re adding native support for Custom API Domains, Object Storage (S3), Pub/Sub, and more! – Remember, you can share your comments and ideas on our Public Roadmap.
As always, if you have questions or feedback, join us on Discord or just reply to this email. We’re excited to hear your feedback! ❤️