Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 488
Yanis Avatar asked May 18 '15 11:05

Yanis


People also ask

Why use Spring in rails?

Spring is a Rails application preloader that speeds up development by keeping your application running in the background. This means you that don't need to restart a server when you make changes. In RubyMine, Spring can be used to run Rails generators, tests, and Rake tasks.

How do you stop springs in rails?

To stop spring you can use bin/spring stop . It should start automatically when you run rails commands.

What is Spring ruby?

Spring is a Ruby on Rails application preloader. It speeds up development by keeping your application running in the background so the application does need to boot it every time you run a test, rake task or migration.


2 Answers

If you want to keep spring in general, you can temporarily disable spring for a single command by prefixing it with the DISABLE_SPRING environment variable:

DISABLE_SPRING=1 bin/rails runner -e production 'MyJob.perform_later'
like image 98
janfoeh Avatar answered Nov 10 '22 22:11

janfoeh


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

like image 23
Kostas Rousis Avatar answered Nov 10 '22 21:11

Kostas Rousis