Another option is to run that code in a container directly inside of fly.
I need this code to make some HTTP requests and then terminate. Unlike the pattern for sidekiq or celery workers, I don’t need the workers to operate indefinitely. Unlike the release_command pattern, I don’t have anything that it’s supposed to “run before”. It feels a lot like a “remote builder”, except the output is not an image.
For now my plan is to use release_command before starting a trivial webserver. Once the webserver is available, I’ll scale the application to zero. This feels gross. Is there a better way?
Yep! Try fly machine run --help. This works similarly to Docker, it will run until it exist by default. If you want, you can specify a restart policy that restarts it on failure.
Ah, yes! That’s not obvious, sorry about that. Machines run within the context of an app. So you either need to create a new app for your one off tasks, or run them within an existing app.
That exposes publicly it on <appname>.fly.dev:<port>. If you are connected via wireguard, you can just use the private IPv6 address to talk to the machine, no port argument necessary.