Skip to content

On a schedule

Shut down staging Machines overnight

Staging Machines stop in the evening and start again before work, and you only get an email if one refuses.

Runs
On a schedule
Apps
Fly.io
AI
Not needed
Access
org or deploy token (read+write)

Send this to your assistant

Create a ClickRuntime automation: on weekdays, stop every Machine in my Fly app 'staging' at 8pm and start them again at 8am. Email me if any stop or start fails.

Paste it into your assistant. It tells you what it will send or change before it runs live.

First time? Adding ClickRuntime to your assistant takes about two minutes.

Why use it

Why teams use this automation

A staging environment on Fly.io usually runs around the clock, though the people who use it work eight or ten hours a day and sleep for the rest. Each Machine is billed for the time it runs, so a staging stack with a web app, a worker and a database costs the same at 3 a.m. on Sunday as at noon on Tuesday. Teams know this and mean to shut things down, but nobody remembers to do it each evening, and nobody wants to be the person who starts it each morning.

On the schedule you set, ClickRuntime lists the Machines in your staging app and stops each one in the evening, then starts them again before the team arrives. If any Machine refuses to stop or start, you get an email naming it, so a failed morning start never surprises anyone.

It suits dev and demo environments rather than production, where Machines should stay up.

What you get out of it

  • Pay only for the hours you use

    Stopped Machines stop accruing compute charges. Running staging for ten hours instead of twenty-four cuts that part of the bill by more than half, every month, with no change to how the team works.

  • Make the saving automatic

    Shutting down by hand depends on someone remembering at six o'clock every day. A schedule does not forget on Fridays or holidays, so the saving shows up in the invoice without anyone doing anything.

  • Have staging ready each morning

    Machines start before people arrive, so the first person in does not wait for a cold start or ask who turned staging off. Work begins when the day does, not after a round of chat messages.

  • Learn about failed starts immediately

    If a Machine does not come back, an email names it. Fixing that at 8 a.m. is better than a developer finding a broken environment at 10 a.m. during a demo.

  • Reduce idle attack surface

    Services that are off cannot be probed overnight. A staging stack with real-looking data and weaker settings is a tempting target, and being offline for fourteen hours a day removes much of that exposure.

How it works

What happens, step by step

  1. Each evening, ClickRuntime lists the Machines in your Fly.io staging app and stops them. Each morning before work, it starts them again.

  2. It handles each Machine one by one and notes any that refuse.

  3. If everything goes through, you hear nothing. If a Machine won't stop or start, you get an email naming it and the reason Fly gave.

Before it runs live

  • Connect Fly.io

What you get

RunsOn a schedule
Shut down staging Machines overnighttoday, 9:00Succeeded
Email · Fly stop failedFly stop failed for 1 Machines in staging lively-frog-112 (3d8d…): 412 machine is in a non-stoppable state

Build your own

Need it to work differently?

This template is a starting point. Copy the prompt and change it, or describe a different automation from scratch, with your own conditions, more apps or an AI step. Your assistant writes it, tests it and runs it on ClickRuntime.
  • Your own rules

    Conditions, thresholds, filters and exceptions, written the way you'd explain them to a colleague.

  • Any number of apps

    One automation can read from one app and update several others. Over 248 apps are ready, and anything with an API works too.

  • AI where it helps

    Summaries, classification, extraction and drafts use ClickRuntime's built-in AI, with no extra key.

  • On a schedule or on each event

    Runs as often as every 5 minutes, or the moment an app sends an event, and keeps track of what it already handled.

Changes you can ask for

  • Run it at a different time, more or less often, or only on weekdays
  • Add an AI step, for example to summarize, sort or draft a reply
  • Add another app, for example also send it to Slack
  • Combine it with other Fly.io steps into one automation

Under the hood

The code that runs this automation

This is the Python script that runs each time the automation starts. Your AI assistant writes it for you when you send the prompt, and you allow each step in your assistant. To change how the automation works, describe the change to your assistant and it updates the script for you. For every function it can use, see the script reference.
stop_and_start_machines_outside_working_hours.pyexample
from datetime import datetime
from zoneinfo import ZoneInfo
from clickruntime import on_trigger, credentials, http, notify

APP = "staging"
API = f"https://api.machines.dev/v1/apps/{APP}/machines"

@on_trigger
def run(event):
    # Scheduled at 8am and 8pm on weekdays: morning starts, evening stops.
    hour = datetime.now(ZoneInfo("Europe/London")).hour
    action = "start" if hour < 12 else "stop"
    headers = {"Authorization": f"Bearer {credentials.secret('FLY_API_TOKEN')}"}
    failed = []
    for m in http.get(API, headers=headers).json():
        resp = http.post(f"{API}/{m['id']}/{action}", headers=headers)
        if resp.status_code != 200:
            failed.append(f"{m['name']} ({m['id']}): {resp.status_code} {resp.text[:200]}")
    if failed:
        notify.email_me(f"Fly {action} failed for {len(failed)} Machines in {APP}", "\n".join(failed))
    return {"action": action, "failed": len(failed)}

FAQ

Common questions

Will stopping Machines lose data?
Stopping a Machine keeps its volumes and configuration, so data on attached volumes remains. Anything held only in memory or in a Machine's temporary disk is lost, so keep important data on volumes or in an external database.
Can weekends be handled differently?
Yes. The schedule can stop Machines on Friday evening and not start them until Monday morning. You can also keep a short list of apps that should stay up or follow different hours. Many teams keep a short exception list too.
Does Fly not already stop idle Machines?
Fly can autostop Machines with no traffic when configured, which works well for web services. A fixed schedule helps with workers and databases that have no incoming traffic, and gives you predictable start times. Check the app's current settings first.
What permissions does it need?
org or deploy token (read+write). Nothing else in your accounts is used.
Does it need AI?
No. It runs without AI, so it doesn't use your plan's AI allowance.
How many runs does it use?
One run each time it runs (on a schedule). Checks that find nothing to do and stop right away aren't counted.
Can I change how it works?
Yes. Describe the change to your AI assistant, for example a different schedule, channel or filter. It updates the automation, tests it and tells you what changed.

Set up “Shut down staging Machines overnight” from your assistant

Copy the prompt above, or connect your assistant first. Free plan, no credit card.