Sidekiq won't shut down after Ctrl+C - ruby-on-rails

I'm using Sidekiq for background operations of my Rails 4.1 app.
When I type Ctrl+C to shutdown Sidekiq, Sidekiq catches the signal but seems to freeze after this last log line:
^C2014-09-18T16:17:19.194Z 20686 TID-ovwtinh0g INFO: Shutting down
2014-09-18T16:17:21.041Z 20686 TID-ovwtixflc INFO: Shutting down 5 quiet workers
Thus, I need another terminal window where I need to type:
bundle exec sidekiqctl stop pidfile
This is really inconvenient (and takes about 8 seconds) and I can't find why Sidekiq won't stop properly with Ctrl+C.
My conf is:
Rails 4.1.5
Sidekiq 3.2.4
Postgresql DB

I came across this same issue. Sidekiq 3.2.4 relies on the Celluloid gem at version 0.16.0, which partially breaks Sidekiq. See here: https://github.com/celluloid/celluloid/issues/457
Update Sidekiq to 3.2.5 which locks Celluloid at version 0.15.2.

It's possible you have another thread in your Sidekiq process which is not stopping, maybe because you are rescuing Exception.

Related

How to check the delayed_job is running or not in Heroku?

Is there any way to check if the delayed_job is running or not?
I have a rails app with delayed_job deployed on heroku. The DJ is running on worker dyno. However, it stopped working yesterday. I checked the worker's status by heroku ps and it's up.
=== worker (Standard-1X): bundle exec rake jobs:work (1)
worker.1: up 2018/03/20 22:06:57 +1100 (~ 19h ago)
And I also went to the rails console to check the queue by Delayed::Job.all and found there are 112 jobs waiting but not executed.
I also checked the logs, but I didn't find any useful information. The worker log just stopped printing yesterday.
Finally, I restarted the worker dyno and it worked again.
heroku restart worker.1
Does there any way to check why the delayed_job was not working in Heroku? Any command in rails console?
Cheers

Does a forked process in Ruby on Rails have a max execution time?

We're running a Rails application which can starts cli commands. The cli commands are like daemons, they should run until they are stopped.
We start them using:
pid = fork do
exec "/path/to/cli"
end
Process.detach(pid)
We're using Puma as application server.
The problem is that the forked processes stop after a period. Is this caused by a max. execution time set in Ruby on Rails or Puma for forked processes?

How can I dedicate threads to run Sidekiq jobs with Puma or Raptor server?

Let's say my process will run 3 workers, and I want to dedicate 1 of them to process web requests, and 2 to handle Sidekiq background jobs, each process potentially being multi-threaded. Is there an easy or best-practices way to handle this? I've tried a few different configurations, but they either give me an error, or just don't process the jobs at all.
I'm using Rails 4 and ActiveJob, but I don't think those points are relevant.
You don't have to take care of sidekiq worker scheduling from you rails application. Sidekiq runs a separate process with the whole rails environment for managing the background workers. Each Worker is a separate Thread, backed by the Celluloid Actor framework. So for your setup you just do the following:
# start a single puma web server process with min 4 and max 16 Threads
$ bundle exec puma -t 4:16
# start a single multithreaded sidekiq process,
# with councurrency settings defined in sidekiq.yml
$ bundle exec sidekiq --pidfile tmp/pids/sidekiq_1.pid
# start another sidekiq process (if really necessary)
$ bundle exec sidekiq --pidfile tmp/pids/sidekiq_2.pid

Is it possible to boot sidekiq (redis server) when we start Rails app using 'rails server'?

I have a Rails application running in Ruby 2.0.0 and Rails 3.2.16. I'm using Sidekiq for setting up background jobs for a lot of automated processes like email delivery, cancellation etc.
Now, I'm starting the rails in one terminal and in next I'm starting the sidekiq.
Rails: rails server -e production
Sidekiq: bundle exec sidekiq -q critical, -q high, -q default, -q low -e production
But, I need to know whether we can start Sidekiq when we start rails itself not running the second command.
Any help would be appreciated. Thanks :)
Look in to foreman and using a Procfile. Then you would use the command foreman start

How do you always have delayed job running on heroku?

I have an app on Heroku running delayed jobs. However at the moment I have to start the job queue running with the terminal command:
heroku rake jobs:work
...but this means when I shut down my terminal the app's delayed job queue shuts down too.
Is there a way I can get Heroku to just always start and run delayed job in the background when the app starts up? Without having to run the command each time and without having it directly linked to my terminal shell?
Thanks very much.
Edit:
It's on the bamboo stack. Upping workers or running rake jobs:work , the delayed jobs runs for a while, but then the queue seems to just stop getting processed. There are no errors in the delayed jobs queue, the workers just stop processing the jobs. It has to explicitly restarted every 5 or 10 mins.
From the docs:
On Heroku's Aspen or Bamboo stack, use heroku workers 1
On the Cedar stack, you put this line in your Procfile:
worker: bundle exec rake jobs:work
And then do heroku scale worker=1.
we use the workless gem with our heroku stack. it starts worker when the delayed_job queue > 0 and quits the worker when delayed_job queue goes to 0.
It turns out that I was using the wrong rake gem.
The following was causing an issues with rails 3 on Heroku:
gem 'rake', '0.9.2'
Updating the gem fixed the issues, even though there were not errors in the log:
gem "rake", "0.8.7"

Resources