How to prevent auto-suspend?

My machine has `auto_stop_machines = "suspend"` (to reduce costs).

I do want to suspend it sometimes, but while running certain tasks I want the machine not to be suspended. How a machine can prevent its own suspension (during it executing a certain task)?

there isn’t any way to pause auto-stop/auto-suspend for a machine while it is running a task; it is based only on incoming requests. I would recommend creating a temporary machine for the task which is not part of the http service, and then setting it to auto_destroy so it goes away once the task is finished.

You could try to send an external request to a noop API. But like Lillian said make a separate worker

External requests won’t stop the automatic suspension. auto_stop_machines is a function of the fly-proxy which makes that decision exclusively based on inbound connections.

The best answer is usually to take control of when your machines stop or suspend yourself. So your config would wind up as:

auto_stop_machines = "off"
auto_start_machines = true

In this setup the proxy will start your machines when they are needed, but will never stop or suspend them. Then, you can stop your own machines by ending your process with a success code, or you can self-suspend from within your own machine:

curl --unix-socket /.fly/api -X POST \
  http://flaps/v1/apps/$FLY_APP_NAME/machines/$FLY_MACHINE_ID/suspend

I mean an external request back to the same apps noop endpoint. That should work right?

Yes, an external request coming in keeps the app alive, though at the point you’re doing that I’d recommend managing the suspend/stop lifecycle directly rather than using the proxy autostop.

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