# Recurring scheduled tasks (like cron)

**URL:** <https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431>\
**Category:** Questions / Help\
**Created:** [May 10, 2021, 10:12pm UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431 "2021-05-10T22:12:31Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![carter](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/carter/32/553_2.png) [@carter](https://community.fly.io/u/carter)\
**Post date:** [May 10, 2021, 10:12pm UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/1 "2021-05-10T22:12:31Z")

</div>

Is there any [fly.io](http://fly.io) recommended way to run scheduled recurring tasks like you would with cron?

From a bit of googling around it seems like a lot of people are recommending running cron jobs from the host, since running cron inside a container isn’t great. Not sure how true that is, but I’m guessing someone else using fly has already built something like this.

My personal use case is having a task run every 10-30 seconds that checks for new config files for a caddy instance (or maybe for multiple caddy instances), if that helps.

---

<div class="post-metadata">

**Author:** ![jsierles](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jsierles/32/595_2.png) [@jsierles](https://community.fly.io/u/jsierles)\
**Post date:** [May 11, 2021, 11:15am UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/2 "2021-05-11T11:15:14Z")

</div>

Also interested in this! Knowing that Fly schedules tasks using Hashicorp Nomad, it wouldn’t be far-fetched to imagine [exposing its built-in support for periodic jobs](https://www.nomadproject.io/docs/job-specification/periodic).

---

<div class="post-metadata">

**Author:** ![jerome](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jerome/32/17_2.png) [@jerome](https://community.fly.io/u/jerome)\
**Post date:** [May 11, 2021, 11:55am UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/3 "2021-05-11T11:55:41Z")

</div>

@carter we’re working on this. Should be available within a few months.

What you’ve been googling about is probably related to containers. We run Docker images as virtual machines (VM). It should be ok (but imperfect) for now to run cron inside your VMs, for your use case.

> [@jsierles](#):
>
> Fly schedules tasks using Hashicorp Nomad, it wouldn’t be far-fetched to imagine [exposing its built-in support for periodic jobs](https://www.nomadproject.io/docs/job-specification/periodic).

Indeed! We’ve been thinking about it for a while. It’s mostly a matter of implementing the logic in our API.

---

<div class="post-metadata">

**Author:** ![eyepulp](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/eyepulp/32/699_2.png) [@eyepulp](https://community.fly.io/u/eyepulp)\
**Post date:** [May 14, 2021, 5:25pm UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/4 "2021-05-14T17:25:19Z")

</div>

@carter / @jerome  
I’m not sure if this relates, but I just [asked a question](https://community.fly.io/t/verifying-services-script-checks-is-supported/1464) about the `[[services.script_checks]]` in a fly.toml, which appears to [support intervals](https://github.com/fly-apps/nginx-cluster/blob/d3f918b65d6c4fca32ce260dd9e11e26af867075/fly.toml#L39-L43)

Not a replacement for cron, but maybe enough? I know it could solve a few things for us, but I’m not 100% sure on its behavior.

---

<div class="post-metadata">

**Author:** ![jerome](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jerome/32/17_2.png) [@jerome](https://community.fly.io/u/jerome)\
**Post date:** [May 14, 2021, 5:29pm UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/5 "2021-05-14T17:29:35Z")

</div>

Yes, that would work right now 🙂

---

<div class="post-metadata">

**Author:** ![jerome](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jerome/32/17_2.png) [@jerome](https://community.fly.io/u/jerome)\
**Post date:** [May 14, 2021, 5:35pm UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/6 "2021-05-14T17:35:21Z")

</div>

I should mention: if you script checks fail, your instance will be “unhealthy” and our scheduler will restart it.

---

<div class="post-metadata">

**Author:** ![eyepulp](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/eyepulp/32/699_2.png) [@eyepulp](https://community.fly.io/u/eyepulp)\
**Post date:** [May 14, 2021, 9:11pm UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/7 "2021-05-14T21:11:21Z")

</div>

@jerome - so we should trap any errors from the script\_check if we don’t want to cause a general restart. That makes sense.

---

<div class="post-metadata">

**Author:** ![danwetherald](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/danwetherald/32/37600_2.png) [@danwetherald](https://community.fly.io/u/danwetherald)\
**Post date:** [October 15, 2021, 6:32pm UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/8 "2021-10-15T18:32:51Z")

</div>

Hey guys, looks like it has been a few months, just checking in on this, what is the best way to run cron scripts today?

I have a new thread going here as this was “solved”:

[https://community.fly.io/t/fly-cron-jobs/2856](https://community.fly.io/t/fly-cron-jobs/2856)

---

<div class="post-metadata">

**Author:** ![jsierles](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jsierles/32/595_2.png) [@jsierles](https://community.fly.io/u/jsierles)\
**Post date:** [October 15, 2021, 6:37pm UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/9 "2021-10-15T18:37:07Z")

</div>

Script checks are going away, so are not a good answer anymore for this. There’s nothing built-in yet, but you could use an external scheduler. Most runtimes have something that can run periodic jobs. Node has [Bree](https://github.com/breejs/bree) and others.

---

<div class="post-metadata">

**Author:** ![danwetherald](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/danwetherald/32/37600_2.png) [@danwetherald](https://community.fly.io/u/danwetherald)\
**Post date:** [October 15, 2021, 6:39pm UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/10 "2021-10-15T18:39:41Z")

</div>

Thanks for that resource, will definitely take a look at this, it looks perfect.

Any plans to have something a bit more native to Fly similar to Heroku?

Let me ask you this, how is [Fly.io](http://Fly.io) doing their internal billing with the Stripe API for metered billing?

I assume you are on a monthly basis running the VM usage calculation and then creating a metered subscription invoice, is this automated? If so, are you using billing thresholds internally? Would love to know more on how you guys are using fly internally to handle billing, etc as this pertains to a use case for us as well.

---

<div class="post-metadata">

**Author:** ![kurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kurt/32/43757_2.png) [@kurt](https://community.fly.io/u/kurt)\
**Post date:** [October 15, 2021, 10:25pm UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/11 "2021-10-15T22:25:09Z")

</div>

We do all our scheduling in process. Periodically triggering VMs is harder than you might think, because you run into issues where one takes too long, another starts, and things get weird.

The simplest thing to do is just run an app with an interval/timer that fires things off every so often.

Our billing is pushing Stripe way past its limits. Each organization gets a subscription with multiple metered products on it. Every hour, we compute usage for disk, memory, CPU, and bandwidth. We send those to Stripe as usage records and it handles the rest.

Stripe billing is not great for metered products. We’ll likely end up doing our own accounting and just create invoices from our code.

---

<div class="post-metadata">

**Author:** ![danwetherald](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/danwetherald/32/37600_2.png) [@danwetherald](https://community.fly.io/u/danwetherald)\
**Post date:** [October 15, 2021, 6:30pm UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/12 "2021-10-15T18:30:10Z")

</div>

Looking for the best way to pull off scheduled jobs similar to Heroku ([Heroku Scheduler | Heroku Dev Center](https://devcenter.heroku.com/articles/scheduler)).

We have a node run time, ideally we would like to run a script from `package.json` every hour for example.

Thanks!

---

<div class="post-metadata">

**Author:** ![carter](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/carter/32/553_2.png) [@carter](https://community.fly.io/u/carter)\
**Post date:** [October 16, 2021, 12:11am UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/13 "2021-10-16T00:11:17Z")

</div>

When are script checks going away?

---

<div class="post-metadata">

**Author:** ![kurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kurt/32/43757_2.png) [@kurt](https://community.fly.io/u/kurt)\
**Post date:** [October 16, 2021, 1:31am UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/14 "2021-10-16T01:31:25Z")

</div>

There is a heisenbug with script checks that causes our VM init to hang. They’re not going away any time soon, but we haven’t been able to track that bug down so we’ve stopped using them. If you have an app that relies on them and they haven’t caused issues, it’s safe to keep using them.

---

<div class="post-metadata">

**Author:** ![danwetherald](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/danwetherald/32/37600_2.png) [@danwetherald](https://community.fly.io/u/danwetherald)\
**Post date:** [October 16, 2021, 3:11am UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/15 "2021-10-16T03:11:21Z")

</div>

Thanks so much for the explanation, this is exactly what we are looking to achieve as well as we have a a subscription for the monthly flat rate, and another subscription that we add for the metered use (transaction fees / revenue shares). We are planning on taking advantage of billing thresholds with this so that AP doesn’t get too high mid month.

To be honest, I honestly would think spinning up a VM on a schedule, running a task, and then shutting down does seem simple from me as a customer haha - This is probably just because in the past in the rails world I would just create different rake tasks, and then use heroku scheduler to run that task on a hourly basis / daily basis / monthly basis, etc.

I would love to learn more on this subject to better understand the complexities of these processes.

Something to be said about using something like [Bree](https://github.com/breejs/bree) is that this requires to have machines running 24/7 possibly doing _nothing_ 99% of the time. From a billing / usage standpoint this is _sort of a waste_.

---

<div class="post-metadata">

**Author:** ![jsierles](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jsierles/32/595_2.png) [@jsierles](https://community.fly.io/u/jsierles)\
**Post date:** [October 16, 2021, 10:04am UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/16 "2021-10-16T10:04:45Z")

</div>

> [@danwetherald](#):
>
> Something to be said about using something like [Bree](https://github.com/breejs/bree) is that this requires to have machines running 24/7 possibly doing _nothing_ 99% of the time. From a billing / usage standpoint this is _sort of a waste_.

This is true - but if your tasks don’t require many resources, a 24/7 small VM comes in at a negligible cost.

Another approach would be to run something like Bree in the same VM as your app. Our [multiple processes](https://fly.io/docs/app-guides/multiple-processes/) guide gives you a few options to do that. I’m a fan of either bash (simple) or [overmind](https://github.com/DarthSim/overmind) which uses the familiar Procfile syntax.

---

<div class="post-metadata">

**Author:** ![danwetherald](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/danwetherald/32/37600_2.png) [@danwetherald](https://community.fly.io/u/danwetherald)\
**Post date:** [October 16, 2021, 3:52pm UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/17 "2021-10-16T15:52:48Z")

</div>

Gotcha, makes sense. I agree that cost is negligible, just thought I would bring this up as a _concern_.

We just spun up a new app and run the bree process (on fly this is $2/month 🥳 )

---

<div class="post-metadata">

**Author:** ![Tv1](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@Tv1](https://community.fly.io/u/Tv1)\
**Post date:** [May 17, 2022, 10:36pm UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/18 "2022-05-17T22:36:55Z")

</div>

I have some use cases where the batch job wants to run with higher privileges than the normal. To illustrate, consider a service with a read-only connection to a data store, and a batch job that updates the data store (in reality, it’s less write access vs more write access).

In another case, they’re even using different software stacks – the always-on VM is a webapp dictated by frameworks to be NodeJS, while the batch jobs are Deno or Go.

It would be great to schedule a “start this VM every X minutes” kind of a thing, where the VM exits when the batch is done.

If you’re worried about old school cron style overruns (the previous instance is still alive when a new one is started), well, you _already_ need to handle that right with block devices! Use that solution. (Ideally in a way that doesn’t waste 1GB for no reason.)

---

<div class="post-metadata">

**Author:** ![arkadiyt](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@arkadiyt](https://community.fly.io/u/arkadiyt)\
**Post date:** [August 27, 2022, 6:43am UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/19 "2022-08-27T06:43:50Z")

</div>

Any updates on this? It seems like it was “a few months away” more than a year ago now

---

<div class="post-metadata">

**Author:** ![atymic](https://avatars.discourse-cdn.com/v4/letter/a/a9adbd/32.png) [@atymic](https://community.fly.io/u/atymic)\
**Post date:** [August 28, 2022, 12:42am UTC](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431/20 "2022-08-28T00:42:22Z")

</div>

This is something that would be great, like what render has.  
Any ETA?

[Next page](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431.md?page=2)
