# wake-on-schedule instead of wake-on-request?

**URL:** <https://community.fly.io/t/wake-on-schedule-instead-of-wake-on-request/10589>\
**Category:** Questions / Help\
**Tags:** login-only\
**Created:** [February 5, 2023, 9:32pm UTC](https://community.fly.io/t/wake-on-schedule-instead-of-wake-on-request/10589 "2023-02-05T21:32:03Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthewadams12](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/matthewadams12/32/9310_2.png) [@matthewadams12](https://community.fly.io/u/matthewadams12)\
**Post date:** [February 5, 2023, 9:32pm UTC](https://community.fly.io/t/wake-on-schedule-instead-of-wake-on-request/10589/1 "2023-02-05T21:32:03Z")

</div>

Hi all,

Is it possible to have my (Docker) app be run on a machine that wakes on a _schedule_, rather than a request? I’d like for Fly to run my app, say, once every 3 hours, then let it exit.

How can I do that?

Thanks,  
Matthew

---

<div class="post-metadata">

**Author:** ![ignoramous](https://avatars.discourse-cdn.com/v4/letter/i/a9adbd/32.png) [@ignoramous](https://community.fly.io/u/ignoramous)\
**Post date:** [February 5, 2023, 10:05pm UTC](https://community.fly.io/t/wake-on-schedule-instead-of-wake-on-request/10589/2 "2023-02-05T22:05:43Z")

</div>

> [@matthewadams12](#):
>
> Is it possible to have my (Docker) app be run on a machine that wakes on a _schedule_, rather than a request? I’d like for Fly to run my app, say, once every 3 hours, then let it exit.

For cron-like flexibility, the setup is a bit more involved: [Crontab with Supercronic · Fly Docs](https://fly.io/docs/app-guides/supercronic/)

With Scheduled Machines, one can only specify `monthly`, `daily`, or `hourly` intervals: [New feature: Scheduled machines](https://community.fly.io/t/new-feature-scheduled-machines/7398)

One can also wake-up their Machine periodically by sending http reqs from an external service like [Durable Object Alarms](https://blog.cloudflare.com/building-scheduling-system-with-workers-and-durable-objects/).

Ref: [Recurring scheduled tasks (like cron)](https://community.fly.io/t/recurring-scheduled-tasks-like-cron/1431)

---

<div class="post-metadata">

**Author:** ![matthewadams12](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/matthewadams12/32/9310_2.png) [@matthewadams12](https://community.fly.io/u/matthewadams12)\
**Post date:** [February 5, 2023, 10:56pm UTC](https://community.fly.io/t/wake-on-schedule-instead-of-wake-on-request/10589/3 "2023-02-05T22:56:58Z")

</div>

It looks like daily scheduled machines will work for me. My app is a dockerized python script that exits after it performs its task, very much like a cloud function.

Is that how the app is expected to behave in a scheduled machine?

---

<div class="post-metadata">

**Author:** ![ignoramous](https://avatars.discourse-cdn.com/v4/letter/i/a9adbd/32.png) [@ignoramous](https://community.fly.io/u/ignoramous)\
**Post date:** [February 6, 2023, 1:03am UTC](https://community.fly.io/t/wake-on-schedule-instead-of-wake-on-request/10589/4 "2023-02-06T01:03:26Z")

</div>

> [@matthewadams12](#):
>
> Is that how the app is expected to behave in a scheduled machine?

Pretty much yes; `sys.exit(0)` should settle the scheduled machine.

---

<div class="post-metadata">

**Author:** ![matthewadams12](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/matthewadams12/32/9310_2.png) [@matthewadams12](https://community.fly.io/u/matthewadams12)\
**Post date:** [February 8, 2023, 6:35pm UTC](https://community.fly.io/t/wake-on-schedule-instead-of-wake-on-request/10589/5 "2023-02-08T18:35:14Z")

</div>

Ok machine created with `--schedule=daily`. Shows as stopped.

I would have expected it to run my script (packaged in my docker image) upon deployment once, then wait 24h before running again. Does it only run after 24h?

---

<div class="post-metadata">

**Author:** ![ignoramous](https://avatars.discourse-cdn.com/v4/letter/i/a9adbd/32.png) [@ignoramous](https://community.fly.io/u/ignoramous)\
**Post date:** [February 8, 2023, 7:32pm UTC](https://community.fly.io/t/wake-on-schedule-instead-of-wake-on-request/10589/6 "2023-02-08T19:32:24Z")

</div>

> [@matthewadams12](#):
>
> I would have expected it to run my script (packaged in my docker image) upon deployment once, then wait 24h before running again. Does it only run after 24h?

I vaguely remember that this was indeed the behaviour. Not sure what changed (or if things have been this way since the beginning). May be @shugel knows…

---

<div class="post-metadata">

**Author:** ![matthewadams12](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/matthewadams12/32/9310_2.png) [@matthewadams12](https://community.fly.io/u/matthewadams12)\
**Post date:** [February 8, 2023, 9:43pm UTC](https://community.fly.io/t/wake-on-schedule-instead-of-wake-on-request/10589/7 "2023-02-08T21:43:18Z")

</div>

What’s the correct `fly` command to upgrade the existing scheduled machine with a newer version of the Docker image?

---

<div class="post-metadata">

**Author:** ![ignoramous](https://avatars.discourse-cdn.com/v4/letter/i/a9adbd/32.png) [@ignoramous](https://community.fly.io/u/ignoramous)\
**Post date:** [February 8, 2023, 10:49pm UTC](https://community.fly.io/t/wake-on-schedule-instead-of-wake-on-request/10589/8 "2023-02-08T22:49:10Z")

</div>

`fly deploy` should _just work_ and update all Machines of the app ([ref](https://community.fly.io/t/fly-apps-on-machine-prerelease/10219)). If not, there’s `fly m update`:

> [@New feature: Scheduled machines](https://community.fly.io/t/new-feature-scheduled-machines/7398/13):
>
> So, the PR (linked above) was merged (and hopefully, isn’t reverted before the next release). This command should build and deploy a new image with schedule intact: # alternatively, specify the --image switch if using a prebuilt fly m update \<machine-id\> --dockerfile \</path/to/file\> -a \<app-name\> I’ll send another PR to fix fly deploy wiping out schedule, in a bit.

---

<div class="post-metadata">

**Author:** ![shugel](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/shugel/32/48662_2.png) [@shugel](https://community.fly.io/u/shugel)\
**Post date:** [February 9, 2023, 10:38am UTC](https://community.fly.io/t/wake-on-schedule-instead-of-wake-on-request/10589/9 "2023-02-09T10:38:34Z")

</div>

Yep, the last time I deployed a new / updated image, it ran immediately.

---

<div class="post-metadata">

**Author:** ![catflydotio](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/catflydotio/32/14559_2.png) [@catflydotio](https://community.fly.io/u/catflydotio)\
**Post date:** [April 27, 2024, 12:28am UTC](https://community.fly.io/t/wake-on-schedule-instead-of-wake-on-request/10589/10 "2024-04-27T00:28:26Z")

</div>

From #How To to #Questions / Help

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/fly1/original/3X/6/e/6e8955d00cb218e186ebbe3a6ab06fefdce15290.svg) [@system](https://community.fly.io/u/system)\
**Post date:** [May 4, 2024, 12:28am UTC](https://community.fly.io/t/wake-on-schedule-instead-of-wake-on-request/10589/11 "2024-05-04T00:28:36Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
