Have you been able to run Sidekiq or a worker process? I could use your help!

Hey folks,

I was wondering if someone could share their experience deploying a Sidekiq worker in fly.io. I’ve gotten to a point that everything builds nicely, but I can’t get the app to actually run the sidekiq command. It spins up the rails server instead.

I’ve got a web instance and redis working nicely together, and I can even see the Sidekiq dashboard. Deployed using the heroku/buildpack:20, and I’ve included the usual Procfile in my repo. Something in the lines of:

web: rails server -p $PORT
worker: sidekiq -C config/sidekiq.yml

For the worker, I created a separate app, modifying the deployment command with the --build-target worker in addition of a separate fly.toml, because the worker app has different needs.(it doesn’t expose any ports, so it skips the services section).

The deployment process picks up those two types, but it seems to set web as default. This is part of the output of the deployment process with the --build-target tag, following Monorepo and Multi-Environment Deployments · Fly.

[INFO] Discovering process types
[INFO] Procfile declares types -> web, worker
Adding layer 'heroku/ruby:env'
Adding layer 'heroku/ruby:gems'
Adding layer 'heroku/ruby:ruby'
Adding 1/1 app layer(s)
Adding layer 'launcher'
Adding layer 'config'
Adding layer 'process-types'
Adding label 'io.buildpacks.lifecycle.metadata'
Adding label 'io.buildpacks.build.metadata'
Adding label 'io.buildpacks.project.metadata'
Setting default process type 'web'

Checking out the logs, it has indeed spawned the web server:

2021-08-19T20:47:20.937896976Z runner[7c197e7a] sjc [info] Starting instance
2021-08-19T20:47:20.960852853Z runner[7c197e7a] sjc [info] Configuring virtual machine
2021-08-19T20:47:20.961883514Z runner[7c197e7a] sjc [info] Pulling container image
2021-08-19T20:47:29.468386049Z runner[7c197e7a] sjc [info] Unpacking image
2021-08-19T20:47:35.273605192Z runner[7c197e7a] sjc [info] Preparing kernel init
2021-08-19T20:47:35.751006639Z runner[7c197e7a] sjc [info] Configuring firecracker
2021-08-19T20:47:35.829986322Z runner[7c197e7a] sjc [info] Starting virtual machine
2021-08-19T20:47:35.955505376Z app[7c197e7a] sjc [info] Starting init (commit: 721b5c7)...
2021-08-19T20:47:35.975021611Z app[7c197e7a] sjc [info] Running: `/cnb/process/web` as heroku
2021-08-19T20:47:35.989098038Z app[7c197e7a] sjc [info] 2021/08/19 20:47:35 listening on [fdaa:0:3197:a7b:ad0:7c19:7e7a:2]:22 (DNS: [fdaa::3]:53)
2021-08-19T20:47:39.037224276Z app[7c197e7a] sjc [info] => Booting Puma
2021-08-19T20:47:39.037730604Z app[7c197e7a] sjc [info] => Rails 6.1.4 application starting in staging
2021-08-19T20:47:39.038408157Z app[7c197e7a] sjc [info] => Run `bin/rails server --help` for more startup options
2021-08-19T20:47:39.777013256Z app[7c197e7a] sjc [info] Puma starting in single mode...
2021-08-19T20:47:39.777643189Z app[7c197e7a] sjc [info] * Puma version: 5.4.0 (ruby 2.7.2-p137) ("Super Flight")
2021-08-19T20:47:39.777940602Z app[7c197e7a] sjc [info] *  Min threads: 5
2021-08-19T20:47:39.778212206Z app[7c197e7a] sjc [info] *  Max threads: 5
2021-08-19T20:47:39.778523165Z app[7c197e7a] sjc [info] *  Environment: staging
2021-08-19T20:47:39.778812693Z app[7c197e7a] sjc [info] *          PID: 510
2021-08-19T20:47:39.779459167Z app[7c197e7a] sjc [info] * Listening on
2021-08-19T20:47:39.788385675Z app[7c197e7a] sjc [info] Use Ctrl-C to stop

Has anyone gone through a similar process? Any help would be appreciated! It’d be nice to keep the Sidekiq workers in a separate app just in case I needed to increase parallelism. Given that this is my first serious deployment on Fly.io I am open to any idea!

1 Like

It’s running the web process since it’s being set as the default:

Setting default process type 'web'

You need to set a different entrypoint for the worker process type, try this in your worker app’s fly.toml:

  entrypoint = ["worker"]

Here’s the buildpack docs for the launcher: Specify launch process · Cloud Native Buildpacks

Also, there’s a rumor going around that multi-process apps will make this a lot easier and are coming soon…

1 Like

Exactly that — Thank you @Michael for the quick solution!!

1 Like

We have a better feature for this in preview, no entrypoint override necessary: Preview: multi process apps (get your workers here!)

1 Like