Yanis T Yanis T - 1 year ago 51
Ruby Question

Rails runner without spring

I have rails 4.2 + sidekiq on ubuntu setup and I'm starting my jobs with cron every hour with something like

bin/rails runner -e production 'MyJob.perform_later'

This basically take a job and puts data to redis, so that sidekiq could take it and start from there. But everytime i do this I have this spring proccesses stuck and waiting for something (consuming memory)

ps aux | grep spring
root Sl 07:13 0:00 spring server | myapp | started 6 secs ago
root Ssl 07:13 0:03 spring app | myapp | started 6 secs ago | production mode

Sometimes I see like 10 of those. Is there any way not to start spring server?

Thank you.

Answer Source

This happens because you are using the spring gem and your bin folder has been "springified".

If you take a look in the bin/rails file you will see that spring is loaded before moving on with running whatever you requested from it.

You could "un-springify" your bin folder by running

bin/spring binstub --remove --all

This would mean of course that you opt out from all performance benefits that spring provides you. This should be OK for production environments. In fact, it is recommended that you do not install spring in your production environments [1].

So I suggest that you modify your Gemfile and place spring under the development group. In production you usually do something like:

bundle install --without development test

That way spring will never make it to your production servers. See also this related issue on Github.


1 . Spring project readme file