sidekiq 2.7.5 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sidekiq might be problematic. Click here for more details.

data/Changes.md CHANGED
@@ -1,3 +1,24 @@
1
+ 2.8.0
2
+ -----------
3
+
4
+ - I18n support! Sidekiq can optionally save and restore the Rails locale
5
+ so it will be properly set when your jobs execute. Just include
6
+ `require 'sidekiq/middleware/i18n'` in your sidekiq initializer. [#750]
7
+ - Fix bug which could lose messages when using namespaces and the message
8
+ needs to be requeued in Redis. [#744]
9
+ - Refactor Redis namespace support [#747]. The redis namespace can no longer be
10
+ passed via the config file, the only supported way is via Ruby in your
11
+ initializer:
12
+
13
+ ```ruby
14
+ sidekiq_redis = { :url => 'redis://localhost:3679', :namespace => 'foo' }
15
+ Sidekiq.configure_server { |config| config.redis = sidekiq_redis }
16
+ Sidekiq.configure_client { |config| config.redis = sidekiq_redis }
17
+ ```
18
+
19
+ A warning is printed out to the log if a namespace is found in your sidekiq.yml.
20
+
21
+
1
22
  2.7.5
2
23
  -----------
3
24
 
@@ -325,6 +325,11 @@ module Sidekiq
325
325
  # allow a non-existent config file so Sidekiq
326
326
  # can be deployed by cap with just the defaults.
327
327
  end
328
+ ns = opts.delete(:namespace)
329
+ if ns
330
+ Sidekiq.logger.warn("namespace should be set in your ruby initializer, is ignored in config file")
331
+ Sidekiq.logger.warn("config.redis = { :url => ..., :namespace => '#{ns}' }")
332
+ end
328
333
  opts
329
334
  end
330
335
 
@@ -78,13 +78,13 @@ module Sidekiq
78
78
  Sidekiq.logger.debug { "Re-queueing terminated jobs" }
79
79
  jobs_to_requeue = {}
80
80
  inprogress.each do |unit_of_work|
81
- jobs_to_requeue[unit_of_work.queue] ||= []
82
- jobs_to_requeue[unit_of_work.queue] << unit_of_work.message
81
+ jobs_to_requeue[unit_of_work.queue_name] ||= []
82
+ jobs_to_requeue[unit_of_work.queue_name] << unit_of_work.message
83
83
  end
84
84
 
85
85
  Sidekiq.redis do |conn|
86
86
  jobs_to_requeue.each do |queue, jobs|
87
- conn.rpush(queue, jobs)
87
+ conn.rpush("queue:#{queue}", jobs)
88
88
  end
89
89
  end
90
90
  Sidekiq.logger.info("Pushed #{inprogress.size} messages back to Redis")
@@ -101,7 +101,7 @@ module Sidekiq
101
101
 
102
102
  def requeue
103
103
  Sidekiq.redis do |conn|
104
- conn.rpush(queue, message)
104
+ conn.rpush("queue:#{queue_name}", message)
105
105
  end
106
106
  end
107
107
  end
@@ -0,0 +1,35 @@
1
+ module Sidekiq::Middleware::I18n
2
+ # Get the current locale and store it in the message
3
+ # to be sent to Sidekiq.
4
+ class Client
5
+ def call(worker_class, msg, queue)
6
+ msg['locale'] = I18n.locale
7
+ yield
8
+ end
9
+ end
10
+
11
+ # Pull the msg locale out and set the current thread to use it.
12
+ class Server
13
+ def call(worker, msg, queue)
14
+ I18n.locale = msg['locale'] || I18n.default_locale
15
+ yield
16
+ ensure
17
+ I18n.locale = nil
18
+ end
19
+ end
20
+ end
21
+
22
+ Sidekiq.configure_client do |config|
23
+ config.client_middleware do |chain|
24
+ chain.add Sidekiq::Middleware::I18n::Client
25
+ end
26
+ end
27
+
28
+ Sidekiq.configure_server do |config|
29
+ config.client_middleware do |chain|
30
+ chain.add Sidekiq::Middleware::I18n::Client
31
+ end
32
+ config.server_middleware do |chain|
33
+ chain.add Sidekiq::Middleware::I18n::Server
34
+ end
35
+ end
@@ -9,7 +9,7 @@ module Sidekiq
9
9
  driver = options[:driver] || 'ruby'
10
10
  # need a connection for Fetcher and Retry
11
11
  size = options[:size] || (Sidekiq.server? ? (Sidekiq.options[:concurrency] + 2) : 5)
12
- namespace = options[:namespace] || Sidekiq.options[:namespace]
12
+ namespace = options[:namespace]
13
13
 
14
14
  ConnectionPool.new(:timeout => 1, :size => size) do
15
15
  build_client(url, namespace, driver)
@@ -60,7 +60,7 @@ module Sidekiq
60
60
 
61
61
  def client_push(opts)
62
62
  jobs << opts
63
- true
63
+ opts.object_id
64
64
  end
65
65
 
66
66
  # Jobs queued for this worker
@@ -1,3 +1,3 @@
1
1
  module Sidekiq
2
- VERSION = "2.7.5"
2
+ VERSION = "2.8.0"
3
3
  end
@@ -5,16 +5,15 @@ Gem::Specification.new do |gem|
5
5
  gem.authors = ["Mike Perham"]
6
6
  gem.email = ["mperham@gmail.com"]
7
7
  gem.description = gem.summary = "Simple, efficient message processing for Ruby"
8
- gem.homepage = "http://mperham.github.com/sidekiq"
8
+ gem.homepage = "http://sidekiq.org"
9
9
  gem.license = "LGPL-3.0"
10
10
 
11
11
  gem.executables = ['sidekiq', 'sidekiqctl']
12
- gem.files = `git ls-files | grep -v myapp`.split("\n")
12
+ gem.files = `git ls-files | grep -Ev '^(myapp|examples)'`.split("\n")
13
13
  gem.test_files = `git ls-files -- test/*`.split("\n")
14
14
  gem.name = "sidekiq"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Sidekiq::VERSION
17
- gem.cert_chain = ['.public_cert.pem']
18
17
  gem.add_dependency 'redis', '~> 3'
19
18
  gem.add_dependency 'redis-namespace'
20
19
  gem.add_dependency 'connection_pool', '~> 1.0'
@@ -4,6 +4,7 @@
4
4
  :require: ./test/fake_env.rb
5
5
  :pidfile: /tmp/sidekiq-config-test.pid
6
6
  :logfile: /tmp/sidekiq.log
7
+ :namespace: sidekiq
7
8
  :concurrency: 50
8
9
  :queues:
9
10
  - [<%="very_"%>often, 2]
@@ -4,6 +4,7 @@ require 'sidekiq/fetch'
4
4
  class TestFetcher < MiniTest::Unit::TestCase
5
5
 
6
6
  def setup
7
+ Sidekiq.redis = { :namespace => 'fuzzy' }
7
8
  Sidekiq.redis do |conn|
8
9
  conn.flushdb
9
10
  conn.rpush('queue:basic', 'msg')
@@ -35,7 +36,7 @@ class TestFetcher < MiniTest::Unit::TestCase
35
36
  assert_equal 0, q1.size
36
37
  assert_equal 0, q2.size
37
38
  uow = Sidekiq::BasicFetch::UnitOfWork
38
- Sidekiq::BasicFetch.bulk_requeue([uow.new('queue:foo', 'bob'), uow.new('queue:foo', 'bar'), uow.new('queue:bar', 'widget')])
39
+ Sidekiq::BasicFetch.bulk_requeue([uow.new('fuzzy:queue:foo', 'bob'), uow.new('fuzzy:queue:foo', 'bar'), uow.new('fuzzy:queue:bar', 'widget')])
39
40
  assert_equal 2, q1.size
40
41
  assert_equal 1, q2.size
41
42
  end
@@ -99,4 +99,28 @@ class TestMiddleware < MiniTest::Unit::TestCase
99
99
  assert_equal [], recorder
100
100
  end
101
101
  end
102
+
103
+ describe 'i18n' do
104
+ before do
105
+ require 'i18n'
106
+ require 'sidekiq/middleware/i18n'
107
+ end
108
+
109
+ it 'saves and restores locale' do
110
+ I18n.locale = 'fr'
111
+ msg = {}
112
+ mw = Sidekiq::Middleware::I18n::Client.new
113
+ mw.call(nil, msg, nil) { }
114
+ assert_equal :fr, msg['locale']
115
+
116
+ msg['locale'] = 'jp'
117
+ I18n.locale = nil
118
+ assert_equal :en, I18n.locale
119
+ mw = Sidekiq::Middleware::I18n::Server.new
120
+ mw.call(nil, msg, nil) do
121
+ assert_equal :jp, I18n.locale
122
+ end
123
+ assert_equal :en, I18n.locale
124
+ end
125
+ end
102
126
  end
@@ -11,30 +11,16 @@ class TestRedisConnection < MiniTest::Unit::TestCase
11
11
  end
12
12
 
13
13
  describe "namespace" do
14
- before do
15
- Sidekiq.options[:namespace] = "xxx"
16
- end
17
-
18
- after do
19
- Sidekiq.options[:namespace] = nil
20
- end
21
-
22
14
  it "uses a given :namespace" do
23
15
  pool = Sidekiq::RedisConnection.create(:namespace => "xxx")
24
16
  assert_equal "xxx", pool.checkout.namespace
25
17
  end
26
18
 
27
- it "uses :namespace from Sidekiq.options" do
28
- pool = Sidekiq::RedisConnection.create
29
- assert_equal "xxx", pool.checkout.namespace
30
- end
31
-
32
19
  it "uses given :namespace over :namespace from Sidekiq.options" do
33
20
  Sidekiq.options[:namespace] = "xxx"
34
21
  pool = Sidekiq::RedisConnection.create(:namespace => "yyy")
35
22
  assert_equal "yyy", pool.checkout.namespace
36
23
  end
37
-
38
24
  end
39
25
  end
40
26
 
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.5
4
+ version: 2.8.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mike Perham
9
9
  autorequire:
10
10
  bindir: bin
11
- cert_chain:
12
- - .public_cert.pem
13
- date: 2013-02-25 00:00:00.000000000 Z
11
+ cert_chain: []
12
+ date: 2013-03-04 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: redis
@@ -198,7 +197,6 @@ extensions: []
198
197
  extra_rdoc_files: []
199
198
  files:
200
199
  - .gitignore
201
- - .public_cert.pem
202
200
  - .travis.yml
203
201
  - COMM-LICENSE
204
202
  - Changes.md
@@ -210,24 +208,6 @@ files:
210
208
  - bin/sidekiq
211
209
  - bin/sidekiqctl
212
210
  - config.ru
213
- - examples/chef/cookbooks/sidekiq/README.rdoc
214
- - examples/chef/cookbooks/sidekiq/recipes/default.rb
215
- - examples/chef/cookbooks/sidekiq/templates/default/monitrc.conf.erb
216
- - examples/chef/cookbooks/sidekiq/templates/default/sidekiq.erb
217
- - examples/chef/cookbooks/sidekiq/templates/default/sidekiq.yml.erb
218
- - examples/clockwork.rb
219
- - examples/config.yml
220
- - examples/monitrc.conf
221
- - examples/por.rb
222
- - examples/runit/README.md
223
- - examples/runit/log/run
224
- - examples/runit/run
225
- - examples/scheduling.rb
226
- - examples/sidekiq
227
- - examples/sinkiq.rb
228
- - examples/upstart/sidekiq.conf
229
- - examples/upstart/workers.conf
230
- - examples/web-ui.png
231
211
  - lib/sidekiq.rb
232
212
  - lib/sidekiq/api.rb
233
213
  - lib/sidekiq/capistrano.rb
@@ -244,6 +224,7 @@ files:
244
224
  - lib/sidekiq/logging.rb
245
225
  - lib/sidekiq/manager.rb
246
226
  - lib/sidekiq/middleware/chain.rb
227
+ - lib/sidekiq/middleware/i18n.rb
247
228
  - lib/sidekiq/middleware/server/active_record.rb
248
229
  - lib/sidekiq/middleware/server/logging.rb
249
230
  - lib/sidekiq/middleware/server/retry_jobs.rb
@@ -304,7 +285,7 @@ files:
304
285
  - web/views/retries.slim
305
286
  - web/views/retry.slim
306
287
  - web/views/scheduled.slim
307
- homepage: http://mperham.github.com/sidekiq
288
+ homepage: http://sidekiq.org
308
289
  licenses:
309
290
  - LGPL-3.0
310
291
  post_install_message:
@@ -1,20 +0,0 @@
1
- -----BEGIN CERTIFICATE-----
2
- MIIDMDCCAhigAwIBAgIBADANBgkqhkiG9w0BAQUFADA+MRAwDgYDVQQDDAdtcGVy
3
- aGFtMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZFgNjb20w
4
- HhcNMTMwMTMwMTkyODU3WhcNMTQwMTMwMTkyODU3WjA+MRAwDgYDVQQDDAdtcGVy
5
- aGFtMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZFgNjb20w
6
- ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC/rvUwLpOQEsPfi1T/QtRj
7
- dc7+0DE8ljILJqJ+sUkZ881Uxit6M+8ZZoqNkwa2e2RCWRBdNx625RQh2bX4utpY
8
- kloTWQ6PBbrDDVHVRAkuwDbaH4wE8rtwXDcKuto4xaHjN+EYWf2rHBNC4+qMX+ev
9
- CD3MRBG7xOURthDpRTKBXTnDA6qPlFH+4BONLyUOPgz2j0hzVQbA/795KJXpIih9
10
- goEiaWzvvqs8upsdFGQoVvaFUKE/Zr79Zm0kNC7dDtG0toHll0XMFUL/JjJT2Rh2
11
- cALDwIxwVdL7r6l2O4qeuXL7HKSC5ZyNqx3JoVwrxfXk2I2DOGBqrGSJJFWUq3i1
12
- AgMBAAGjOTA3MAkGA1UdEwQCMAAwHQYDVR0OBBYEFNGAnRmrLLc4NFfTSL2PjpAx
13
- GJnfMAsGA1UdDwQEAwIEsDANBgkqhkiG9w0BAQUFAAOCAQEAf9vqK2frmnKcyDE7
14
- dt9eLthYUxZ8HlctLSXDs4tjlEKKfwkD1Yalu4PNzhjrHqXa8hYTxqHPfWmV771q
15
- qT/OLVvL4ofjrXmAG+hqwzcT7grSbYDAK14ITY8M8DpC2jvuGR3MnyChi9ep0pLa
16
- E9Jy35lxa3UFBjr0neI9QxowMilmjUHnPDzVHbzmWAQxPoc18uiU9PXd0h+Jsx2F
17
- y8Ix+zZ1LIOWk9O9WnMdLOTjUFnA/zutM3Nzv8zNBnUJjH5/A5igCIAL+6vU7+su
18
- sLF+JCFPbBgvRqL5hX03CKuyOUNmUVT5AnCDnfIDUV/kJhX7Wfr6IqaUHmUcy/jn
19
- ey6hlw==
20
- -----END CERTIFICATE-----
@@ -1,11 +0,0 @@
1
- = DESCRIPTION:
2
-
3
- Sidekiq is a Redis-backed Ruby library for creating background jobs, placing those jobs on multiple queues, and processing them later.
4
-
5
- = USAGE:
6
-
7
- add require_recipe "sidekiq" to main/recipes/default.rb
8
-
9
- = NOTES:
10
-
11
- I setup a basic size for the Sidekiq workers based on the instance_type, if you need more or less workers please modify the recipe itself.
@@ -1,55 +0,0 @@
1
- #
2
- # Cookbook Name:: sidekiq
3
- # Recipe:: default
4
- #
5
- role = node[:instance_role]
6
- if role == 'solo' || (role == 'util' && node[:name] =~ /sidekiq/)
7
-
8
- # for now
9
- worker_count = 1
10
-
11
- node[:applications].each do |app, data|
12
- template "/etc/monit.d/sidekiq_#{app}.monitrc" do
13
- owner 'root'
14
- group 'root'
15
- mode 0644
16
- source "monitrc.conf.erb"
17
- variables({
18
- :num_workers => worker_count,
19
- :app_name => app,
20
- :rails_env => node[:environment][:framework_env]
21
- })
22
- end
23
-
24
- template "/engineyard/bin/sidekiq" do
25
- owner 'root'
26
- group 'root'
27
- mode 0755
28
- source "sidekiq.erb"
29
- end
30
-
31
- worker_count.times do |count|
32
- template "/data/#{app}/shared/config/sidekiq_#{count}.yml" do
33
- owner node[:owner_name]
34
- group node[:owner_name]
35
- mode 0644
36
- source "sidekiq.yml.erb"
37
- variables({
38
- :require => "/data/#{app}/current"
39
- })
40
- end
41
- end
42
-
43
- execute "ensure-sidekiq-is-setup-with-monit" do
44
- command %Q{
45
- monit reload
46
- }
47
- end
48
-
49
- execute "restart-sidekiq" do
50
- command %Q{
51
- echo "sleep 20 && monit -g #{app}_sidekiq restart all" | at now
52
- }
53
- end
54
- end
55
- end
@@ -1,8 +0,0 @@
1
- <% (@num_workers || 1).times do |num| %>
2
- check process sidekiq_<%= @app_name %>_<%= num %>
3
- with pidfile /var/run/engineyard/sidekiq/<%= @app_name %>/sidekiq_<%= num %>.pid
4
- start program = "/engineyard/bin/sidekiq <%= @app_name %> start <%= @rails_env %> sidekiq_<%= num %>.yml" with timeout 90 seconds
5
- stop program = "/engineyard/bin/sidekiq <%= @app_name %> stop <%= @rails_env %> sidekiq_<%= num %>.yml" with timeout 90 seconds
6
- if totalmem is greater than 300 MB for 2 cycles then restart # eating up memory?
7
- group <%= @app_name %>_sidekiq
8
- <% end %>
@@ -1,180 +0,0 @@
1
- #!/bin/sh
2
- #
3
- # This script starts and stops the Sidekiq daemon
4
- # This script belongs in /engineyard/bin/sidekiq
5
- #
6
-
7
- PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
8
- CURDIR=`pwd`
9
-
10
- usage() {
11
- echo "Usage: $0 <appname> {start|stop|quit} <environment> <conf_file>"
12
- echo -e "\nstop) is a synonym for quit"
13
- echo "quit) issues -INT to request the worker to stop"
14
- echo -e "\nSee http://mperham.github.com/sidekiq/ for more details"
15
- exit 1
16
- }
17
-
18
- rm_lockfile(){
19
- if [ -e $LOCK_FILE ]; then
20
- logger -t "monit-sidekiq[$$]" "removing $LOCK_FILE for `cat $LOCK_FILE`"
21
- rm $LOCK_FILE
22
- fi
23
- }
24
-
25
- exit_cleanly() {
26
- cd $CURDIR
27
- logger -t "monit-sidekiq[$$]" "exiting wrapper cleanly with $RESULT"
28
- exit $RESULT
29
- }
30
-
31
- unlock_and_exit_cleanly(){
32
- rm_lockfile
33
- exit_cleanly
34
- }
35
-
36
- set_pid_from_file(){
37
- export PID=`cat $PID_FILE`
38
- }
39
-
40
- signal_worker() {
41
- RESULT=0
42
- if [ -f $PID_FILE ]; then
43
- set_pid_from_file
44
- logger -t "monit-sidekiq[$$]" "Issuing kill with -$SIG $PID"
45
- kill -$SIG $PID
46
- fi
47
- }
48
-
49
- lock(){
50
- RESULT=0
51
- if [ -e $LOCK_FILE ]; then
52
- LAST_LOCK_PID=`cat $LOCK_FILE`
53
- if [ -n $LAST_LOCK_PID -a -z "`ps axo pid|grep $LAST_LOCK_PID`" -a -f $LOCK_FILE ];then
54
- sleep 1
55
- logger -t "monit-sidekiq[$$]" "Removing stale lock file for $WORKER_REF ($LAST_LOCK_PID)"
56
- rm $LOCK_FILE 2>&1
57
- else
58
- logger -t "monit-sidekiq[$$]" "Monit already messing with $WORKER_REF ($LAST_LOCK_PID)"
59
- RESULT=1
60
- exit_cleanly
61
- fi
62
- fi
63
- echo $$ > $LOCK_FILE
64
- }
65
-
66
- legacy_fix() {
67
- #In the transition from 0.18.2 to 0.18.3 of ey monit scripts the way
68
- #the pid file is used to find the process to kill has changed.
69
- #To avert problems being left behind after an upgrade of this package,
70
- if [ -f $PID_FILE ]; then
71
- set_pid_from_file
72
- if [ -n "`ps axo pid,command|grep $PID|grep 'su -c'`" ];then
73
- logger -t "monit-sidekiq[$$]" "Monit Scripts have just been upgraded, killing old style workers"
74
- for child in $(ps axo pid,ppid| awk "{ if ( \$2 == $PID ) { print \$1 }}");
75
- do
76
- kill -TERM $child 2> /dev/null
77
- while [ -e /proc/$child ]; do
78
- logger -t "monit-sidekiq[$$]" "killing legacy worker: $child"
79
- [ -e /proc/$child ] && kill -9 $child 2> /dev/null
80
- sleep 1
81
- done
82
- done
83
- [ -e /proc/$PID ] && kill -9 $PID 2> /dev/null
84
- rm $PID_FILE
85
- unlock_exit_cleanly
86
- fi
87
- fi
88
- }
89
-
90
- if [ $# -lt 4 ]; then usage; fi
91
-
92
- if [ "`whoami`" != "root" ]; then
93
- logger -t `basename $0` -s "Must be run as root"
94
- exit 1
95
- fi
96
-
97
- #Baisc Setup of default values
98
- APP=$1 ; ACTION=$2; RACK_ENV=$3; CONF_FILE=$4;
99
-
100
- APP_DIR="/data/${APP}"
101
- APP_ROOT="${APP_DIR}/current"
102
- APP_SHARED="${APP_DIR}/shared"
103
- APP_CONFIG="${APP_SHARED}/config"
104
-
105
- if [ -e "${APP_CONFIG}/${CONF_FILE}" ]; then
106
- logger -t "sidekiq_${APP}" -s "Good, found a conf file. Proceeding..."
107
- else
108
- logger -t "sidekiq_${APP}" -s "/data/${APP}/shared/config/${CONF_FILE} not found for app: ${APP}"
109
- exit 1
110
- fi
111
-
112
- WORKER_REF=`echo $CONF_FILE | sed s/.yml//`
113
- LOG_FILE="$APP_ROOT/log/$WORKER_REF.log"
114
- LOCK_FILE="/tmp/$WORKER_REF.monit-lock"
115
- PID_FILE="/var/run/engineyard/sidekiq/$APP/$WORKER_REF.pid"
116
- GEMFILE="$APP_ROOT/Gemfile"
117
- SIDEKIQ="sidekiq"
118
- if [ -f $GEMFILE ];then
119
- SIDEKIQ="$APP_ROOT/ey_bundler_binstubs/sidekiq"
120
- fi
121
-
122
- if [ -d $APP_ROOT ]; then
123
- USER=$(stat -L -c"%U" $APP_ROOT)
124
- export HOME="/home/$USER"
125
-
126
- # Fix for SD-3786 - stop sending in VERBOSE= and VVERBOSE= by default
127
- if declare -p VERBOSE >/dev/null 2>&1; then export V="VERBOSE=$VERBOSE"; fi
128
- if declare -p VVERBOSE >/dev/null 2>&1; then export VV="VVERBOSE=$VVERBOSE"; fi
129
-
130
- # Older versions of sudo need us to call env for the env vars to be set correctly
131
- COMMAND="/usr/bin/env $V $VV APP_ROOT=${APP_ROOT} RACK_ENV=${RACK_ENV} RAILS_ENV=${RACK_ENV} $SIDEKIQ -e ${RACK_ENV} -C ${APP_CONFIG}/${CONF_FILE}"
132
-
133
- if [ ! -d /var/run/engineyard/sidekiq/$APP ]; then
134
- mkdir -p /var/run/engineyard/sidekiq/$APP
135
- fi
136
-
137
- # handle the second param, don't start if already existing
138
-
139
- logger -t "monit-sidekiq[$$]" "${ACTION}ing Sidekiq worker $WORKER_REF"
140
- case "$ACTION" in
141
- start)
142
- lock
143
- cd $APP_ROOT
144
- if [ -f $PID_FILE ]; then
145
- set_pid_from_file
146
- if [ -d /proc/$PID ]; then
147
- logger -t "monit-sidekiq[$$]" "Sidekiq worker $WORKER_REF is already running with $PID."
148
- RESULT=1
149
- else
150
- rm -f $PID_FILE
151
- logger -t "monit-sidekiq[$$]" "Removing stale pid file ($PID_FILE) for pid $PID"
152
- fi
153
- fi
154
- if [ ! -f $PID_FILE ]; then
155
- sudo -u $USER -H $COMMAND >> $LOG_FILE 2>&1 &
156
- RESULT=$?
157
- logger -t "monit-sidekiq[$$]" "Started with pid $! and exit $RESULT"
158
- echo $! > $PID_FILE
159
- sleep .1
160
- fi
161
- unlock_and_exit_cleanly
162
- ;;
163
- stop|quit)
164
- legacy_fix
165
- lock
166
- SIG="INT"
167
- signal_worker
168
- [ -e "$LOCK_FILE" ] && rm $LOCK_FILE
169
- unlock_and_exit_cleanly
170
- ;;
171
- *)
172
- usage
173
- exit_cleanly
174
- ;;
175
- esac
176
- else
177
- echo "/data/$APP/current doesn't exist."
178
- usage
179
- fi
180
-
@@ -1,22 +0,0 @@
1
- ---
2
- <% if @verbose %>
3
- :verbose: <%= @verbose %>
4
- <% end %>
5
- <% if @environment %>
6
- :environment: <%= @environment %>
7
- <% end %>
8
- <% if @require %>
9
- :require: <%= @require %>
10
- <% end %>
11
- <% if @pidfile %>
12
- :pidfile: <%= @pidfile %>
13
- <% end %>
14
- <% if @concurrency %>
15
- :concurrency: <%= @concurrency %>
16
- <% end %>
17
- <% if @queues %>
18
- :queues:
19
- <% @queues.each do |name, priority| %>
20
- - [<%= name %>, <%= priority %>]
21
- <% end %>
22
- <% end %>
@@ -1,44 +0,0 @@
1
- # Sidekiq defers scheduling to other, better suited gems.
2
- # If you want to run a job regularly, here's an example
3
- # of using the 'clockwork' gem to push jobs to Sidekiq
4
- # regularly.
5
-
6
- # require boot & environment for a Rails app
7
- # require_relative "../config/boot"
8
- # require_relative "../config/environment"
9
- require "clockwork"
10
-
11
- class MyWorker
12
- include Sidekiq::Worker
13
-
14
- def perform(count)
15
- puts "Job ##{count}: Late night, so tired..."
16
- end
17
-
18
- def self.late_night_work
19
- 10.times do |x|
20
- perform_async(x)
21
- end
22
- end
23
- end
24
-
25
- class HourlyWorker
26
- include Sidekiq::Worker
27
-
28
- def perform
29
- cleanup_database
30
- format_hard_drive
31
- end
32
- end
33
-
34
- module Clockwork
35
- # Kick off a bunch of jobs early in the morning
36
- every 1.day, 'my_worker.late_night_work', :at => '4:30 am' do
37
- MyWorker.late_night_work
38
- end
39
-
40
- every 1.hour do
41
- HourlyWorker.perform_async
42
- end
43
- end
44
-
@@ -1,12 +0,0 @@
1
- # Sample configuration file for Sidekiq.
2
- # Options here can still be overridden by cmd line args.
3
- # sidekiq -C config.yml
4
- ---
5
- :verbose: false
6
- :pidfile: ./tmp/pids/sidekiq.pid
7
- :namespace: sidekiq_namespace
8
- :concurrency: 25
9
- :queues:
10
- - [often, 7]
11
- - [default, 5]
12
- - [seldom, 3]
@@ -1,6 +0,0 @@
1
- check process sidekiq_myapp
2
- with pidfile /path/to/sidekiq.pid
3
- start program = "bundle exec sidekiq -C /path/to/sidekiq_conf.yml -P /path/to/sidekiq.pid" with timeout 90 seconds
4
- stop program = "kill -s INT `cat /path/to/sidekiq.pid`" with timeout 90 seconds
5
- if totalmem is greater than 200 MB for 2 cycles then restart # eating up memory?
6
- group myapp_sidekiq
@@ -1,27 +0,0 @@
1
- require 'sidekiq'
2
-
3
- # If your client is single-threaded, we just need a single connection in our Redis connection pool
4
- Sidekiq.configure_client do |config|
5
- config.redis = { :namespace => 'x', :size => 1, :url => 'redis://redis.host:1234/14' }
6
- end
7
-
8
- # Sidekiq server is multi-threaded so our Redis connection pool size defaults to concurrency (-c)
9
- Sidekiq.configure_server do |config|
10
- config.redis = { :namespace => 'x', :url => 'redis://redis.host:1234/14' }
11
- end
12
-
13
- # Start up sidekiq via
14
- # ./bin/sidekiq -r ./examples/por.rb
15
- # and then you can open up an IRB session like so:
16
- # irb -r ./examples/por.rb
17
- # where you can then say
18
- # PlainOldRuby.perform_async "like a dog", 3
19
- #
20
- class PlainOldRuby
21
- include Sidekiq::Worker
22
-
23
- def perform(how_hard="super hard", how_long=1)
24
- sleep how_long
25
- puts "Workin' #{how_hard}"
26
- end
27
- end
@@ -1,16 +0,0 @@
1
- This is a "service" directory for sidekiq. You should probably modify
2
- the relevant paths in the run script, and the log/run script, if
3
- necessary. It assumes a "sidekiq" user is created that will run the
4
- sidekiq process. To supervise under runit, link this directory to the
5
- runsvdir for your system (e.g., `/etc/service` on Debian/Ubuntu).
6
-
7
- If you're using Chef, use the
8
- [example cookbook](https://github.com/mperham/sidekiq/tree/master/examples/chef/cookbooks/sidekiq)
9
- (modified for your environment), and Opscode's
10
- [runit cookbook](http://ckbk.it/runit) to set up the service.
11
-
12
- Author: Joshua Timberman <joshua@opscode.com>
13
-
14
- Runit is written by Gerrit Pape.
15
-
16
- * http://smarden.org/runit
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- exec svlogd -tt /var/log/sidekiq
@@ -1,4 +0,0 @@
1
- #!/bin/sh
2
- cd /path/to/sidekiq
3
- exec 2>&1
4
- exec chpst -usidekiq bundle exec sidekiq -e production -P /var/run/sidekiq/sidekiq.pid
@@ -1,37 +0,0 @@
1
- # Sidekiq defers scheduling cron-like tasks to other, better suited gems.
2
- # If you want to run a job regularly, here's an example
3
- # of using the 'whenever' gem to push jobs to Sidekiq
4
- # regularly.
5
-
6
- class MyWorker
7
- include Sidekiq::Worker
8
-
9
- def perform(count)
10
- puts "Job ##{count}: Late night, so tired..."
11
- end
12
-
13
- def self.late_night_work
14
- 10.times do |x|
15
- perform_async(x)
16
- end
17
- end
18
- end
19
-
20
- # Kick off a bunch of jobs early in the morning
21
- every 1.day, :at => '4:30 am' do
22
- runner "MyWorker.late_night_work"
23
- end
24
-
25
-
26
- class HourlyWorker
27
- include Sidekiq::Worker
28
-
29
- def perform
30
- cleanup_database
31
- format_hard_drive
32
- end
33
- end
34
-
35
- every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot
36
- runner "HourlyWorker.perform_async"
37
- end
@@ -1,92 +0,0 @@
1
- #!/bin/bash
2
- # sidekiq Init script for Sidekiq
3
- # chkconfig: 345 100 75
4
- #
5
- # Description: Starts and Stops Sidekiq message processor for Stratus application.
6
- #
7
- # User-specified exit parameters used in this script:
8
- #
9
- # Exit Code 5 - Incorrect User ID
10
- # Exit Code 6 - Directory not found
11
-
12
-
13
- #Variable Set
14
- APP="stratus"
15
- APP_DIR="/opt/railsapps/${APP}"
16
- APP_CONFIG="${APP_DIR}/config"
17
- LOG_FILE="$APP_DIR/log/sidekiq.log"
18
- LOCK_FILE="$APP_DIR/${APP}-lock"
19
- PID_FILE="$APP_DIR/${APP}.pid"
20
- GEMFILE="$APP_DIR/Gemfile"
21
- SIDEKIQ="sidekiq"
22
- APP_ENV="production"
23
- BUNDLE="bundle"
24
-
25
- START_CMD="$BUNDLE exec $SIDEKIQ -e $APP_ENV -P $PID_FILE"
26
- RETVAL=0
27
-
28
-
29
- start() {
30
-
31
- status
32
- if [ $? -eq 1 ]; then
33
-
34
- [ `id -u` == '0' ] || (echo "$SIDEKIQ runs as root only .."; exit 5)
35
- [ -d $APP_DIR ] || (echo "$APP_DIR not found!.. Exiting"; exit 6)
36
- cd $APP_DIR
37
- echo "Starting $SIDEKIQ message processor .. "
38
- $START_CMD >> $LOG_FILE 2>&1 &
39
- RETVAL=$?
40
- #Sleeping for 8 seconds for process to be precisely visible in process table - See status ()
41
- sleep 8
42
- [ $RETVAL -eq 0 ] && touch $LOCK_FILE
43
- return $RETVAL
44
- else
45
- echo "$SIDEKIQ message processor is already running .. "
46
- fi
47
-
48
-
49
- }
50
-
51
- stop() {
52
-
53
- echo "Stopping $SIDEKIQ message processor .."
54
- SIG="INT"
55
- kill -$SIG `cat $PID_FILE`
56
- RETVAL=$?
57
- [ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
58
- return $RETVAL
59
- }
60
-
61
-
62
- status() {
63
-
64
- ps -ef | grep 'sidekiq [0-9].[0-9].[0-9]' | grep -v grep
65
- return $?
66
- }
67
-
68
-
69
- case "$1" in
70
- start)
71
- start
72
- ;;
73
- stop)
74
- stop
75
- ;;
76
- status)
77
- status
78
-
79
- if [ $? -eq 0 ]; then
80
- echo "$SIDEKIQ message processor is running .."
81
- RETVAL=0
82
- else
83
- echo "$SIDEKIQ message processor is stopped .."
84
- RETVAL=1
85
- fi
86
- ;;
87
- *)
88
- echo "Usage: $0 {start|stop|status}"
89
- exit 0
90
- ;;
91
- esac
92
- exit $RETVAL
@@ -1,60 +0,0 @@
1
- # Make sure you have Sinatra installed, then start sidekiq with
2
- # ./bin/sidekiq -r ./examples/sinkiq.rb
3
- # Simply run Sinatra with
4
- # ruby examples/sinkiq.rb
5
- # and then browse to http://localhost:4567
6
- #
7
- require 'sinatra'
8
- require 'sidekiq'
9
- require 'redis'
10
-
11
- $redis = Redis.connect
12
-
13
- class SinatraWorker
14
- include Sidekiq::Worker
15
-
16
- def perform(msg="lulz you forgot a msg!")
17
- $redis.lpush("sinkiq-example-messages", msg)
18
- end
19
- end
20
-
21
- get '/' do
22
- stats = Sidekiq::Stats.new
23
- @failed = stats.failed
24
- @processed = stats.processed
25
- @messages = $redis.lrange('sinkiq-example-messages', 0, -1)
26
- erb :index
27
- end
28
-
29
- post '/msg' do
30
- SinatraWorker.perform_async params[:msg]
31
- redirect to('/')
32
- end
33
-
34
- __END__
35
-
36
- @@ layout
37
- <html>
38
- <head>
39
- <title>Sinatra + Sidekiq</title>
40
- <body>
41
- <%= yield %>
42
- </body>
43
- </html>
44
-
45
- @@ index
46
- <h1>Sinatra + Sidekiq Example</h1>
47
- <h2>Failed: <%= @failed %></h2>
48
- <h2>Processed: <%= @processed %></h2>
49
-
50
- <form method="post" action="/msg">
51
- <input type="text" name="msg">
52
- <input type="submit" value="Add Message">
53
- </form>
54
-
55
- <a href="/">Refresh page</a>
56
-
57
- <h3>Messages</h3>
58
- <% @messages.each do |msg| %>
59
- <p><%= msg %></p>
60
- <% end %>
@@ -1,46 +0,0 @@
1
- # /etc/init/sidekiq.conf - Sidekiq config
2
-
3
- # This example config should work with Ubuntu 12.04+. It
4
- # allows you to manage multiple Sidekiq instances with
5
- # Upstart, Ubuntu's native service management tool.
6
- #
7
- # See workers.conf for how to manage all Sidekiq instances at once.
8
- #
9
- # Save this config as /etc/init/sidekiq.conf then mange sidekiq with:
10
- # sudo start sidekiq index=0
11
- # sudo stop sidekiq index=0
12
- # sudo status sidekiq index=0
13
- #
14
- # or use the service command:
15
- # sudo service sidekiq {start,stop,restart,status}
16
- #
17
-
18
- description "Sidekiq Background Worker"
19
-
20
- # no "start on", we don't want to automatically start
21
- stop on (stopping workers or runlevel [06])
22
-
23
- # change to match your deployment user
24
- setuid deploy
25
- setgid deploy
26
-
27
- respawn
28
- respawn limit 3 30
29
-
30
- instance $index
31
-
32
- script
33
- # this script runs in /bin/sh by default
34
- # respawn as bash so we can source in rbenv
35
- exec /bin/bash <<EOT
36
- # use syslog for logging
37
- exec &> /dev/kmsg
38
-
39
- # pull in system rbenv
40
- export HOME=/home/deploy
41
- source /etc/profile.d/rbenv.sh
42
-
43
- cd /opt/theclymb/current
44
- exec bin/sidekiq -i ${index} -e production -C config/sidekiq.yml -P tmp/pids/sidekiq-${index}.pid
45
- EOT
46
- end script
@@ -1,30 +0,0 @@
1
- # /etc/init/workers.conf - manage a set of Sidekiqs
2
-
3
- # This example config should work with Ubuntu 12.04+. It
4
- # allows you to manage multiple Sidekiq instances with
5
- # Upstart, Ubuntu's native service management tool.
6
- #
7
- # See sidekiq.conf for how to manage a single Sidekiq instance.
8
- #
9
- # Use "stop workers" to stop all Sidekiq instances.
10
- # Use "start workers" to start all instances.
11
- # Use "restart workers" to restart all instances.
12
- # Crazy, right?
13
- #
14
-
15
- description "manages the set of sidekiq processes"
16
-
17
- # This starts upon bootup and stops on shutdown
18
- start on runlevel [2345]
19
- stop on runlevel [06]
20
-
21
- # Set this to the number of Sidekiq processes you want
22
- # to run on this machine
23
- env NUM_WORKERS=2
24
-
25
- pre-start script
26
- for i in `seq 0 $((${NUM_WORKERS} - 1))`
27
- do
28
- start sidekiq index=$i
29
- done
30
- end script
Binary file