`fly.toml` for private background worker

Hi there,

I would like to deploy a background worker without any http_service. There should be exactly one instance of the worker, and it should not be publicly accessible.

My question is: what should the fly.toml look like?

I have a Dockerfile ready to deploy. The program just loops, and jobs are fired off interally based on a cron expression. All it does is make external API calls and save some data to a database.

This is my current fly.toml

app = "my-background-worker"
primary_region = "jnb"

And I am deploying from a monorepo with the following command

flyctl deploy --config ./my-background-worker/fly.toml --dockerfile ./my-background-worker/fly.toml

So far, it seems to be working. After deploying, fly creates a single machine with the Dockerfile running and it seems to be staying alive. How can I ensure that there is exactly one of these running at all times? It should never be scaled down to 0, and never scaled up beyond 1.

Thanks!
Emilio

Hi @emilioziniades

Since the auto stop and stop feature only applies to Machines with services, you shouldn’t see any automatic scaling happening with this setup.

I’d suggest setting the Machine restart policy to always so that your Machine restarts if the host ever reboots. You can read more about restart policies here, but the important bit in your case is:

To set the Machine restart policy to always, run:

fly m update --restart always <your machine id>

1 Like

Hey @andie,

Thanks for your response. That post is very helpful. I’ll update the restart policy via CLI.

From that thread, it seems like it’s not yet possible to set the restart policy via fly.toml, right? Looking forward to being able to do that.

That’s correct. Right now, restart policy is only applied per Machine.

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