A La Carte Options?

I need to keep my server alive to run a function once a day. Is there a method to either ensure that my server is alive at X time for X duration or is there something I can buy to keep it alive? I’d upgrade to the $29 paid plan, but that is incredibly expensive for my needs. I essentially could go spend $10 for a droplet but wanted to give Fly a try.

Hi there,

Having a plan is not a requirement, if you don’t have a plan and want to scale beyond the included free allowances, you can pay for just what you need at the usage-based pricing listed here. Paid plans are useful if you need more support or compliance options.

My concern is not it scaling in that manner. My concern is the server going to sleep when I need it awake to run a function.

Depends on your needs!

If you need something akin to cron, where it has a scheduled time to consistently execute a command, there’s limited support for scheduling in the --schedule flag for fly machine run.

If your app just needs to respond to infrequent requests, you can use autostart/stop to run a service that is only live when it’s in use, and then pauses until another request can wake it.

1 Like

I briefed over the auto start and stop. If I understand it correctly if I set start to true, and stop to false the machine will never turn off thus never entering an idle state where my server job which is on a queue / timer will always be active and I don’t have to concern about it not running?

They recommend setting both to true, or both to false.

If you set both too true, and don’t give a minimum (another field), then ALL will run off.

When a request comes in, it will spin up real quick. This is the same tech that powers Lambda, so the “cold start” typically is very fast.

It depends on how fast your app starts, but the ability for a request to wake a server is near instant. It’s very impressive.

For a HTTP service for example, you might have in your fly.toml,

[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0

You actually don’t need the min_machines_running set if its zero, that is the default.

If you need to schedule, you can spin the machine up, like above. Then you use the CLI to set a basic schedule on it.

Either way the cost of the servers can be very cheap, it all depends on your needs.

I’m not understanding what this “run off” means… essentially what I need to do is every morning at 0815 is start the machine, it needs to stay alive for 30 min or until the function has completed its task. Would that mean that both need to be true?

Sorry, I meant to say “turn off” not “run off”.

My understanding is that the machine will stay alive for as long as a task/process is receiving connections. I believe it may also stay alive by understanding that a active process is running on it.

For example I use LiteFS with sqlite3 to sync data between servers, and it won’t exit while data is being transmitted.

Additionally, if it fits within the free tier, you can just set min machines to one, and leave one running. If your service can run on a shared-1x and low memory, that would be a few dollars a month, well below the free tier.

But I have a feeling you can keep the system up. For example if you did ENTRYPOINT sleep infinity in your dockerfile, I think it would stay up forever. So you can see how you could use a script to handle this.

Ok! I don’t believe this usecase is what autostop/start helps with.

So, to do this, the closest we’ve got is fly m run --schedule <sched>. Schedule doesn’t accept a time, though, it accepts “monthly”, “weekly”, “daily”, “hourly”. (for more info, here’s a post about that)

Unfortunately, I don’t believe we currently offer granular scheduling at this time. It’s either the loose “daily” scheduling, or keeping the machine running indefinitely and just running something like cron inside of it.

1 Like

Another alternative: you can run a Machine full-time if you want to, and do something like Crontab with Supercronic · Fly Docs. If I recall previous forum topics correctly, cron itself can work, too.

To keep a Machine running 24/7 in an app deployed with fly deploy, make sure auto_stop_machines = false in fly.toml.

Note that a single Machine is literally a VM running on some hardware – it’s not a more abstract serverless job. You may want to think a bit about how much redundancy you need in case of a single-host failure. App Availability and Resiliency · Fly Docs

1 Like

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