jondot/sneakers

How to automatically spawn workers in Rails

Closed this issue · 5 comments

I'm sorry if this feels like a noob question, but i read the Wiki up and down and can't seem to find the proper way to do this.

I have an app server which will be listening for messages, so i want a Worker to always be running. The server's running on Passenger and we don't use Procfile, so foreman is not an option. Of course, i don't want to manually do rake sneakers:run each time the server is updated, restarted or cloned.

The question seems silly to me because it's such a simple thing, but i can't see from the docs what is the correct way to do it (maybe lack of experience). I've already tried simply doing

class ProcessingDoneWorker
  include Sneakers::Worker
  ...
end

Thread.new do
  Sneakers::Runner.new([ProcessingDoneWorker]).run
end

but this seems to spawn a new one every so often (while i only want one) and admittedly was just a quick and ugly solution. Putting the same code elsewhere creates similar or different problems.

@MartinCura thanks for using sneakers and for calling out some possible gaps in our documentation.

How do you deploy your application?

Thanks for the response!

Locally i just use docker-compose, rails server with Puma. For production it's an Elastic Beanstalk we use Phusion Passenger (with Ruby 2.4 running on 64bit Amazon Linux/2.9.3). Thus it's Rack-based, if i'm not mistaken, and we have a minimalist config.ru.

  • locally - You should just be able to add rake sneakers:run to your docker-compose.yml file so when you do docker-compose up it runs both rails and sneakers
  • aws - i'm not sure how you would pull this off in one process off the top of my head. see if this blog post section has a lead.

I think i had ran into that post, but i didn't follow that section because it seemed about something else (it doesn't even mention Sneakers).

Anyway, at least for the moment i just replaced the Sneakers worker with Bunny::subscribe. It's uglier, but good enough for our rather simple use case, at least for the moment. If Sneakers gets an easier way to run its Workers, i'll consider switching back.

Thanks for your help anyway :)

np. thanks for the question.