I need to run multiple instances of Sidekiq on a machine that is hosting multiple different Rails apps. In order to avoid conflicts, I had one of my apps use a different redis instance, pointed at 127.0.0.1/1 instead of the default 127.0.0.1/0, by using the following code in my config/initializers/sidekiq.rb
Sidekiq.configure_client do |config|
config.redis = { :url => 'redis://127.0.0.1:6379/1' }
end
When I boot my instance of Sidekiq using bundle exec sidekiq I get the following boot message:
2015-02-04T16:46:59.494Z 15104 TID-ovz94l9m0 INFO: Running in ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
2015-02-04T16:46:59.494Z 15104 TID-ovz94l9m0 INFO: See LICENSE and the LGPL-3.0 for licensing details.
2015-02-04T16:46:59.494Z 15104 TID-ovz94l9m0 INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org/pro
2015-02-04T16:46:59.494Z 15104 TID-ovz94l9m0 INFO: Starting processing, hit Ctrl-C to stop
2015-02-04T16:46:59.541Z 15104 TID-ovz9c4dhk INFO: Booting Sidekiq 3.3.0 with redis options {}
The problem is that I want
2015-02-04T16:46:59.541Z 15104 TID-ovz9c4dhk INFO: Booting Sidekiq 3.3.0 with redis options {:url => 'redis://127.0.0.1:6379/1'}
instead. What command line options to boot Sidekiq or what config files should I edit to have Sidekiq boot with the redis options reflected in config/initializers/sidekiq.rb?
You must set the Redis config in both the configure_client and configure_server blocks. You are starting the server. More info here:
https://github.com/mperham/sidekiq/wiki/Using-Redis
Related
I'm trying to run a Rails 6 app on AWS Elastic Beanstalk, but I get from puma log the following (repeats every few seconds)
[21776] + Gemfile in context: /var/app/current/Gemfile
[21776] Early termination of worker
The version numbers:
Rails 6.0.3.3
puma 4.3.5
ElasticBeanstalk Ruby 2.7 running on 64bit Amazon Linux 2/3.1.1
ruby 2.7.1p83
The server is unresponsive from outside the instance, and there's nothing on log/production.log.
Running on a dev machine on production mode there's no errors, and the database is reachable (no migration failure).
Running on the AWS instance the command bundle exec puma -p 3000 -e production I get
Puma starting in single mode...
Version 4.3.5 (ruby 2.7.1-p83), codename: Mysterious Traveller
Min threads: 5, max threads: 5
Environment: production
Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
so there's no obvious error that may cause the worker to halt.
How can I find out what's causing the workers to fail?
Edit 1:
I ran Rails console on the instance and found that the environment variables are missing - e.g. the production database user/pass/host. Once I hardcoded them I could connect to the database.
I suspect the absence of other environment variables is making the app crash.
A user on AWS forum had the answer.
Setting in my Gemfile
gem "nio4r", "= 2.5.2"
fixed the issue.
I'm trying to run Sidekiq 5.2.2 on Rails 5.2 but I always get a connection lost error. Below are my server logs:
# bundle exec sidekiq -q v2_default,2 -q v2_low -e production
TID-2yed0 INFO: Booting Sidekiq 5.2.2 with redis options {:url=>"redis://myserver.lmf979.0001.apse1.cache.amazonaws.com:6379/1", :network_timeout=>7, :id=>"Sidekiq-server-PID-3644"}
TID-2yed0 INFO: Running in ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-linux]
TID-2yed0 INFO: See LICENSE and the LGPL-3.0 for licensing details.
TID-2yed0 INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org
TID-2yed0 INFO: Starting processing, hit Ctrl-C to stop
TID-19spa0 ERROR: heartbeat: Connection lost (ECONNRESET)
TID-xhh1g ERROR: Error fetching job: READONLY You can't write against a read only slave.
TID-xhh1g WARN: Redis::CommandError: READONLY You can't write against a read only slave.
TID-xhh1g WARN: /usr/local/rvm/gems/ruby-2.3.5/gems/redis-4.0.2/lib/redis/client.rb:119:in `call'
and this is my config/initializers/sidekiq.rb
Sidekiq.configure_server do |config|
config.redis = { url: 'redis://myserver.lmf979.0001.apse1.cache.amazonaws.com:6379/1', network_timeout: 7 }
end
Sidekiq.configure_client do |config|
config.redis = { url: 'redis://myserver.lmf979.0001.apse1.cache.amazonaws.com:6379/1', network_timeout: 7 }
end
I verify that I can do ping PONG with the server but I don't know why sidekiq can't connect.
# rails c production
Running via Spring preloader in process 7372
Loading production environment (Rails 5.2.1)
2.3.5 :001 > require "redis"
=> false
2.3.5 :002 > redis = Redis.new(url: 'redis://myserver.lmf979.0001.apse1.cache.amazonaws.com:6379/1')
=> #<Redis client v4.0.2 for redis://myserver.lmf979.0001.apse1.cache.amazonaws.com:6379/1>
2.3.5 :003 > redis.ping
=> "PONG"
2.3.5 :004 >
Any ideas?
I was just pointing to a wrong redis endpoint in AWS. Thanks to Pavel Mikhailyuk for pointing out.
Having followed the rails-cast (http://railscasts.com/episodes/271-resque?view=comments), I was able to setup my rails application similarly with worker and rake tasks.
However, as specified in the rails-cast, once I start my rails server, I have to issue the following command in a separate terminal window:
TERM_CHILD=1 QUEUES=* rake resque:work
This gets me up-and-running and I have no issues. However, instead of firing off a rake command on terminal (or writing a startup shell script), I would like to issue this terminal command (TERM_CHILD=1 QUEUES=* rake resque:work) from Rails itself when the application starts up so its available during the duration of the application's uptime on the server.
I am in the process of learning Rails framework so I would greatly appreciate if you can give me some help and let me know how/where to place any code snippet you may provide me with.
Thank you very much in advance.
Here are my environment specs:
I am using jruby (jruby 1.7.16.1 (1.9.3p392) 2014-10-28 4e93f31 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_72-b14 +jit [linux-amd64])
Rails version 4.1.8
I am developing on LINUX ubuntu 14.04
I will be deploying this application to Windows 2008 server on a Tomcat server as a WAR package
I am using PostgreSQL as my database.
That approach would make it difficult to turn off your resque workers. I recommend using a common gem called foreman to handle this. I'll let you look a the documentation, but your Procfile would look something like:
web: rails s -p $PORT
resque: TERM_CHILD=1 QUEUES=* rake resque:work
And you would be able to start both rails and resque by just running the foreman command in console. That will also allow you to exit out of both easily.
Updated per OP's message:
require 'resque/tasks'
ENV['TERM_CHILD'] = 1
ENV['QUEUES'] = '*'
Thread.new { Rake::Task["resque:work"] }
The Thread.new is there because it would otherwise cause the rest of the app to never load.
I'm trying to get my rails app to run in production mode but I've been having a bit of difficulty.
I'm using passenger with apache and am running Ubuntu 12.04. I have my production database configured and created, and passenger set up. Status is as follows:
$ rvmsudo passenger-status
Version : 4.0.56
Date : 2014-12-25 01:54:20 +0000
Instance: 7264
----------- General information -----------
Max pool size : 6
Processes : 0
Requests in top-level queue : 0
----------- Application groups -----------
However when I run rails server -e production, it still listens on port 3000 see below:
$ rails server -e production
=> Booting WEBrick
=> Rails 4.2.0 application starting in production on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-12-25 01:54:49] INFO WEBrick 1.3.1
[2014-12-25 01:54:49] INFO ruby 2.1.5 (2014-11-13) [i686-linux]
[2014-12-25 01:54:49] INFO WEBrick::HTTPServer#start: pid=7459 port=3000
What might I be missing to get it to listens on port 80 in production mode?
Many thanks in advance.
I don't think this is how you have to start the server in production using Apache. Did you install apache-paassenger modules? and made changes in apache conf file?
First, the gem needs to be installed on the system:
gem install passenger
Before the Apache module is compiled, two dependency packages need to be installed as well:
apt-get install curl-devel httpd-devel
Use this command to start the apache installation: It will take some time
passenger-install-apache2-module
Passenger will display some content after Apache installs:
Follow it up and make changes in (/etc/httpd/conf/httpd.conf)
You will have to point to application public folder and restart the apache server follow with these sources closely.
https://www.digitalocean.com/community/tutorials/how-to-install-rails-apache-and-mysql-on-ubuntu-with-passenger
https://www.digitalocean.com/community/tutorials/how-to-setup-a-rails-4-app-with-apache-and-passenger-on-centos-6
It helped when I did it for first time.
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.