sidekiq 2.15.1 → 4.2.10

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.

Files changed (187) hide show
  1. checksums.yaml +7 -0
  2. data/.github/contributing.md +32 -0
  3. data/.github/issue_template.md +9 -0
  4. data/.gitignore +1 -0
  5. data/.travis.yml +16 -17
  6. data/3.0-Upgrade.md +70 -0
  7. data/4.0-Upgrade.md +53 -0
  8. data/COMM-LICENSE +56 -44
  9. data/Changes.md +644 -1
  10. data/Ent-Changes.md +173 -0
  11. data/Gemfile +27 -0
  12. data/LICENSE +1 -1
  13. data/Pro-2.0-Upgrade.md +138 -0
  14. data/Pro-3.0-Upgrade.md +44 -0
  15. data/Pro-Changes.md +457 -3
  16. data/README.md +46 -29
  17. data/Rakefile +6 -3
  18. data/bin/sidekiq +4 -0
  19. data/bin/sidekiqctl +41 -20
  20. data/bin/sidekiqload +154 -0
  21. data/code_of_conduct.md +50 -0
  22. data/lib/generators/sidekiq/templates/worker.rb.erb +9 -0
  23. data/lib/generators/sidekiq/templates/worker_spec.rb.erb +6 -0
  24. data/lib/generators/sidekiq/templates/worker_test.rb.erb +8 -0
  25. data/lib/generators/sidekiq/worker_generator.rb +49 -0
  26. data/lib/sidekiq.rb +141 -29
  27. data/lib/sidekiq/api.rb +540 -106
  28. data/lib/sidekiq/cli.rb +131 -71
  29. data/lib/sidekiq/client.rb +168 -96
  30. data/lib/sidekiq/core_ext.rb +36 -8
  31. data/lib/sidekiq/exception_handler.rb +20 -28
  32. data/lib/sidekiq/extensions/action_mailer.rb +25 -5
  33. data/lib/sidekiq/extensions/active_record.rb +8 -4
  34. data/lib/sidekiq/extensions/class_methods.rb +9 -5
  35. data/lib/sidekiq/extensions/generic_proxy.rb +1 -0
  36. data/lib/sidekiq/fetch.rb +45 -101
  37. data/lib/sidekiq/launcher.rb +144 -30
  38. data/lib/sidekiq/logging.rb +69 -12
  39. data/lib/sidekiq/manager.rb +90 -140
  40. data/lib/sidekiq/middleware/chain.rb +18 -5
  41. data/lib/sidekiq/middleware/i18n.rb +9 -2
  42. data/lib/sidekiq/middleware/server/active_record.rb +1 -1
  43. data/lib/sidekiq/middleware/server/logging.rb +11 -11
  44. data/lib/sidekiq/middleware/server/retry_jobs.rb +98 -44
  45. data/lib/sidekiq/paginator.rb +20 -8
  46. data/lib/sidekiq/processor.rb +157 -96
  47. data/lib/sidekiq/rails.rb +109 -5
  48. data/lib/sidekiq/redis_connection.rb +70 -24
  49. data/lib/sidekiq/scheduled.rb +122 -50
  50. data/lib/sidekiq/testing.rb +171 -31
  51. data/lib/sidekiq/testing/inline.rb +1 -0
  52. data/lib/sidekiq/util.rb +31 -5
  53. data/lib/sidekiq/version.rb +2 -1
  54. data/lib/sidekiq/web.rb +136 -263
  55. data/lib/sidekiq/web/action.rb +93 -0
  56. data/lib/sidekiq/web/application.rb +336 -0
  57. data/lib/sidekiq/web/helpers.rb +278 -0
  58. data/lib/sidekiq/web/router.rb +100 -0
  59. data/lib/sidekiq/worker.rb +40 -7
  60. data/sidekiq.gemspec +18 -14
  61. data/web/assets/images/favicon.ico +0 -0
  62. data/web/assets/images/{status-sd8051fd480.png → status.png} +0 -0
  63. data/web/assets/javascripts/application.js +67 -19
  64. data/web/assets/javascripts/dashboard.js +138 -29
  65. data/web/assets/stylesheets/application.css +267 -406
  66. data/web/assets/stylesheets/bootstrap.css +4 -8
  67. data/web/locales/cs.yml +78 -0
  68. data/web/locales/da.yml +9 -1
  69. data/web/locales/de.yml +18 -9
  70. data/web/locales/el.yml +68 -0
  71. data/web/locales/en.yml +19 -4
  72. data/web/locales/es.yml +10 -1
  73. data/web/locales/fa.yml +79 -0
  74. data/web/locales/fr.yml +50 -32
  75. data/web/locales/hi.yml +75 -0
  76. data/web/locales/it.yml +27 -18
  77. data/web/locales/ja.yml +27 -12
  78. data/web/locales/ko.yml +8 -3
  79. data/web/locales/{no.yml → nb.yml} +19 -5
  80. data/web/locales/nl.yml +8 -3
  81. data/web/locales/pl.yml +0 -1
  82. data/web/locales/pt-br.yml +11 -4
  83. data/web/locales/pt.yml +8 -1
  84. data/web/locales/ru.yml +39 -21
  85. data/web/locales/sv.yml +68 -0
  86. data/web/locales/ta.yml +75 -0
  87. data/web/locales/uk.yml +76 -0
  88. data/web/locales/zh-cn.yml +68 -0
  89. data/web/locales/zh-tw.yml +68 -0
  90. data/web/views/_footer.erb +17 -0
  91. data/web/views/_job_info.erb +72 -60
  92. data/web/views/_nav.erb +58 -25
  93. data/web/views/_paging.erb +5 -5
  94. data/web/views/_poll_link.erb +7 -0
  95. data/web/views/_summary.erb +20 -14
  96. data/web/views/busy.erb +94 -0
  97. data/web/views/dashboard.erb +34 -21
  98. data/web/views/dead.erb +34 -0
  99. data/web/views/layout.erb +8 -30
  100. data/web/views/morgue.erb +75 -0
  101. data/web/views/queue.erb +37 -30
  102. data/web/views/queues.erb +26 -20
  103. data/web/views/retries.erb +60 -47
  104. data/web/views/retry.erb +23 -19
  105. data/web/views/scheduled.erb +39 -35
  106. data/web/views/scheduled_job_info.erb +2 -1
  107. metadata +152 -195
  108. data/Contributing.md +0 -29
  109. data/config.ru +0 -18
  110. data/lib/sidekiq/actor.rb +0 -7
  111. data/lib/sidekiq/capistrano.rb +0 -54
  112. data/lib/sidekiq/yaml_patch.rb +0 -21
  113. data/test/config.yml +0 -11
  114. data/test/env_based_config.yml +0 -11
  115. data/test/fake_env.rb +0 -0
  116. data/test/helper.rb +0 -42
  117. data/test/test_api.rb +0 -341
  118. data/test/test_cli.rb +0 -326
  119. data/test/test_client.rb +0 -211
  120. data/test/test_exception_handler.rb +0 -124
  121. data/test/test_extensions.rb +0 -105
  122. data/test/test_fetch.rb +0 -44
  123. data/test/test_manager.rb +0 -83
  124. data/test/test_middleware.rb +0 -135
  125. data/test/test_processor.rb +0 -160
  126. data/test/test_redis_connection.rb +0 -97
  127. data/test/test_retry.rb +0 -306
  128. data/test/test_scheduled.rb +0 -86
  129. data/test/test_scheduling.rb +0 -47
  130. data/test/test_sidekiq.rb +0 -37
  131. data/test/test_testing.rb +0 -82
  132. data/test/test_testing_fake.rb +0 -265
  133. data/test/test_testing_inline.rb +0 -92
  134. data/test/test_util.rb +0 -18
  135. data/test/test_web.rb +0 -372
  136. data/web/assets/images/bootstrap/glyphicons-halflings-white.png +0 -0
  137. data/web/assets/images/bootstrap/glyphicons-halflings.png +0 -0
  138. data/web/assets/images/status/active.png +0 -0
  139. data/web/assets/images/status/idle.png +0 -0
  140. data/web/assets/javascripts/locales/README.md +0 -27
  141. data/web/assets/javascripts/locales/jquery.timeago.ar.js +0 -96
  142. data/web/assets/javascripts/locales/jquery.timeago.bg.js +0 -18
  143. data/web/assets/javascripts/locales/jquery.timeago.bs.js +0 -49
  144. data/web/assets/javascripts/locales/jquery.timeago.ca.js +0 -18
  145. data/web/assets/javascripts/locales/jquery.timeago.cy.js +0 -20
  146. data/web/assets/javascripts/locales/jquery.timeago.cz.js +0 -18
  147. data/web/assets/javascripts/locales/jquery.timeago.da.js +0 -18
  148. data/web/assets/javascripts/locales/jquery.timeago.de.js +0 -18
  149. data/web/assets/javascripts/locales/jquery.timeago.el.js +0 -18
  150. data/web/assets/javascripts/locales/jquery.timeago.en-short.js +0 -20
  151. data/web/assets/javascripts/locales/jquery.timeago.en.js +0 -20
  152. data/web/assets/javascripts/locales/jquery.timeago.es.js +0 -18
  153. data/web/assets/javascripts/locales/jquery.timeago.et.js +0 -18
  154. data/web/assets/javascripts/locales/jquery.timeago.fa.js +0 -22
  155. data/web/assets/javascripts/locales/jquery.timeago.fi.js +0 -28
  156. data/web/assets/javascripts/locales/jquery.timeago.fr-short.js +0 -16
  157. data/web/assets/javascripts/locales/jquery.timeago.fr.js +0 -17
  158. data/web/assets/javascripts/locales/jquery.timeago.he.js +0 -18
  159. data/web/assets/javascripts/locales/jquery.timeago.hr.js +0 -49
  160. data/web/assets/javascripts/locales/jquery.timeago.hu.js +0 -18
  161. data/web/assets/javascripts/locales/jquery.timeago.hy.js +0 -18
  162. data/web/assets/javascripts/locales/jquery.timeago.id.js +0 -18
  163. data/web/assets/javascripts/locales/jquery.timeago.it.js +0 -16
  164. data/web/assets/javascripts/locales/jquery.timeago.ja.js +0 -19
  165. data/web/assets/javascripts/locales/jquery.timeago.ko.js +0 -17
  166. data/web/assets/javascripts/locales/jquery.timeago.lt.js +0 -20
  167. data/web/assets/javascripts/locales/jquery.timeago.mk.js +0 -20
  168. data/web/assets/javascripts/locales/jquery.timeago.nl.js +0 -20
  169. data/web/assets/javascripts/locales/jquery.timeago.no.js +0 -18
  170. data/web/assets/javascripts/locales/jquery.timeago.pl.js +0 -31
  171. data/web/assets/javascripts/locales/jquery.timeago.pt-br.js +0 -16
  172. data/web/assets/javascripts/locales/jquery.timeago.pt.js +0 -16
  173. data/web/assets/javascripts/locales/jquery.timeago.ro.js +0 -18
  174. data/web/assets/javascripts/locales/jquery.timeago.rs.js +0 -49
  175. data/web/assets/javascripts/locales/jquery.timeago.ru.js +0 -34
  176. data/web/assets/javascripts/locales/jquery.timeago.sk.js +0 -18
  177. data/web/assets/javascripts/locales/jquery.timeago.sl.js +0 -44
  178. data/web/assets/javascripts/locales/jquery.timeago.sv.js +0 -18
  179. data/web/assets/javascripts/locales/jquery.timeago.th.js +0 -20
  180. data/web/assets/javascripts/locales/jquery.timeago.tr.js +0 -16
  181. data/web/assets/javascripts/locales/jquery.timeago.uk.js +0 -34
  182. data/web/assets/javascripts/locales/jquery.timeago.uz.js +0 -19
  183. data/web/assets/javascripts/locales/jquery.timeago.zh-CN.js +0 -20
  184. data/web/assets/javascripts/locales/jquery.timeago.zh-TW.js +0 -20
  185. data/web/views/_poll.erb +0 -14
  186. data/web/views/_workers.erb +0 -29
  187. data/web/views/index.erb +0 -16
data/README.md CHANGED
@@ -1,36 +1,43 @@
1
1
  Sidekiq
2
2
  ==============
3
3
 
4
- [![Gem Version](https://badge.fury.io/rb/sidekiq.png)](https://rubygems.org/gems/sidekiq) [![Code Climate](https://codeclimate.com/github/mperham/sidekiq.png)](https://codeclimate.com/github/mperham/sidekiq) [![Build Status](https://travis-ci.org/mperham/sidekiq.png)](https://travis-ci.org/mperham/sidekiq) [![Coverage Status](https://coveralls.io/repos/mperham/sidekiq/badge.png?branch=master)](https://coveralls.io/r/mperham/sidekiq)
4
+ [![Gem Version](https://badge.fury.io/rb/sidekiq.svg)](https://rubygems.org/gems/sidekiq)
5
+ [![Code Climate](https://codeclimate.com/github/mperham/sidekiq.svg)](https://codeclimate.com/github/mperham/sidekiq)
6
+ [![Build Status](https://travis-ci.org/mperham/sidekiq.svg)](https://travis-ci.org/mperham/sidekiq)
7
+ [![Gitter Chat](https://badges.gitter.im/mperham/sidekiq.svg)](https://gitter.im/mperham/sidekiq)
5
8
 
6
9
 
7
10
  Simple, efficient background processing for Ruby.
8
11
 
9
12
  Sidekiq uses threads to handle many jobs at the same time in the
10
13
  same process. It does not require Rails but will integrate tightly with
11
- Rails 3/4 to make background processing dead simple.
14
+ Rails to make background processing dead simple.
12
15
 
13
16
  Sidekiq is compatible with Resque. It uses the exact same
14
17
  message format as Resque so it can integrate into an existing Resque processing farm.
15
18
  You can have Sidekiq and Resque run side-by-side at the same time and
16
19
  use the Resque client to enqueue jobs in Redis to be processed by Sidekiq.
17
20
 
18
- At the same time, Sidekiq uses multithreading so it is much more memory efficient than
19
- Resque (which forks a new process for every job). You'll find that you might need
20
- 50 200MB resque processes to peg your CPU whereas one 300MB Sidekiq process will peg
21
- the same CPU and perform the same amount of work.
21
+ Performance
22
+ ---------------
23
+
24
+ Version | Latency | Garbage created for 10,000 jobs | Time to process 100,000 jobs | Throughput
25
+ -----------------|------|---------|---------|------------------------
26
+ Sidekiq 4.0.0 | 10ms | 151 MB | 22 sec | **4500 jobs/sec**
27
+ Sidekiq 3.5.1 | 22ms | 1257 MB | 125 sec | 800 jobs/sec
28
+ Resque 1.25.2 | - | - | 420 sec | 240 jobs/sec
29
+ DelayedJob 4.1.1 | - | - | 465 sec | 215 jobs/sec
22
30
 
23
31
 
24
32
  Requirements
25
33
  -----------------
26
34
 
27
- I test with the latest Ruby (2.0) and JRuby versions (1.7). Other versions/VMs
28
- are untested but might work fine.
35
+ Sidekiq supports CRuby 2.0+ and JRuby 9k.
29
36
 
30
- The last two major Rails releases (3.2 and 4.0) are officially supported, other
31
- versions might work fine.
37
+ All Rails releases >= 3.2 are officially supported.
32
38
 
33
- Redis 2.4 or greater is required.
39
+ Redis 2.8 or greater is required. 3.0.3+ is recommended for large
40
+ installations with thousands of worker threads.
34
41
 
35
42
 
36
43
  Installation
@@ -42,8 +49,9 @@ Installation
42
49
  Getting Started
43
50
  -----------------
44
51
 
45
- See the [sidekiq home page](http://mperham.github.com/sidekiq) for the simple 3-step process.
46
- You can watch [Railscast #366](http://railscasts.com/episodes/366-sidekiq) to see Sidekiq in action. If you do everything right, you should see this:
52
+ See the [Getting Started wiki page](https://github.com/mperham/sidekiq/wiki/Getting-Started) and follow the simple setup process.
53
+ You can watch [this Youtube playlist](https://www.youtube.com/playlist?list=PLjeHh2LSCFrWGT5uVjUuFKAcrcj5kSai1) to learn all about
54
+ Sidekiq and see its features in action. Here's the Web UI:
47
55
 
48
56
  ![Web UI](https://github.com/mperham/sidekiq/raw/master/examples/web-ui.png)
49
57
 
@@ -51,31 +59,40 @@ You can watch [Railscast #366](http://railscasts.com/episodes/366-sidekiq) to se
51
59
  Want to Upgrade?
52
60
  -------------------
53
61
 
54
- I also sell Sidekiq Pro, an extension to Sidekiq which provides more
55
- features, a commercial-friendly license and allows you to support high
62
+ I also sell Sidekiq Pro and Sidekiq Enterprise, extensions to Sidekiq which provide more
63
+ features, a commercial-friendly license and allow you to support high
56
64
  quality open source development all at the same time. Please see the
57
- [Sidekiq Pro](http://sidekiq.org/pro) homepage for more detail.
65
+ [Sidekiq](http://sidekiq.org/) homepage for more detail.
66
+
67
+ Subscribe to the **[quarterly newsletter](https://tinyletter.com/sidekiq)** to stay informed about the latest
68
+ features and changes to Sidekiq and its bigger siblings.
58
69
 
59
70
 
60
- More Information
71
+ Problems?
61
72
  -----------------
62
73
 
63
- Please see the [sidekiq wiki](https://github.com/mperham/sidekiq/wiki) for more information.
64
- [#sidekiq on irc.freenode.net](irc://irc.freenode.net/#sidekiq) is dedicated to this project,
65
- but bug reports or feature requests suggestions should still go through [issues on Github](https://github.com/mperham/sidekiq/issues).
74
+ **Please do not directly email any Sidekiq committers with questions or problems.** A community is best served when discussions are held in public.
66
75
 
67
- There's also a mailing list via [Librelist](http://librelist.org) that you can subscribe to by sending
68
- an email to <sidekiq@librelist.org> with a greeting in the body. To unsubscribe, send an email to <sidekiq-unsubscribe@librelist.org> and that's it!
69
- Once archiving begins, you'll be able to visit [the archives](http://librelist.com/browser/sidekiq/) to see past threads.
76
+ If you have a problem, please review the [FAQ](https://github.com/mperham/sidekiq/wiki/FAQ) and [Troubleshooting](https://github.com/mperham/sidekiq/wiki/Problems-and-Troubleshooting) wiki pages.
77
+ Searching the [issues](https://github.com/mperham/sidekiq/issues) for your problem is also a good idea.
70
78
 
79
+ Useful resources:
71
80
 
72
- Problems?
73
- -----------------
81
+ * Product documentation is in the [wiki](https://github.com/mperham/sidekiq/wiki).
82
+ * Release announcements are made to the [@sidekiq](https://twitter.com/sidekiq) Twitter account.
83
+ * Here's a [Reddit forum](https://reddit.com/r/sidekiq) dedicated to Sidekiq discussion
84
+ * The [Sidekiq tag](https://stackoverflow.com/questions/tagged/sidekiq) on Stack Overflow has lots of useful Q &amp; A.
74
85
 
75
- **Please do not directly email any Sidekiq committers with questions or problems.** A community is best served when discussions are held in public.
86
+ **No support via Twitter, 140 characters is not enough.**
87
+
88
+ Every Friday morning is Sidekiq happy hour: I video chat and answer questions.
89
+ See the [Sidekiq support page](http://sidekiq.org/support) for details.
90
+
91
+ Thanks
92
+ -----------------
76
93
 
77
- If you have a problem, please review the [FAQ](https://github.com/mperham/sidekiq/wiki/FAQ) and [Troubleshooting](https://github.com/mperham/sidekiq/wiki/Problems-and-Troubleshooting) wiki pages. Searching the issues for your problem is also a good idea. If that doesn't help, feel free to email the Sidekiq mailing list or open a new issue.
78
- The mailing list is the preferred place to ask questions on usage. If you are encountering what you think is a bug, please open an issue.
94
+ Sidekiq stays fast by using the [JProfiler java profiler](http://www.ej-technologies.com/products/jprofiler/overview.html) to find and fix
95
+ performance problems on JRuby. Unfortunately MRI does not have good multithreaded profiling tools.
79
96
 
80
97
 
81
98
  License
@@ -87,4 +104,4 @@ Please see [LICENSE](https://github.com/mperham/sidekiq/blob/master/LICENSE) for
87
104
  Author
88
105
  -----------------
89
106
 
90
- Mike Perham, [@mperham](https://twitter.com/mperham), [http://mikeperham.com](http://mikeperham.com)
107
+ Mike Perham, [@mperham](https://twitter.com/mperham) / [@sidekiq](https://twitter.com/sidekiq), [http://www.mikeperham.com](http://www.mikeperham.com) / [http://www.contribsys.com](http://www.contribsys.com)
data/Rakefile CHANGED
@@ -1,9 +1,12 @@
1
+ require 'bundler/gem_tasks'
1
2
  require 'rake/testtask'
2
3
  Rake::TestTask.new(:test) do |test|
3
- test.libs << 'test'
4
- #SO MUCH NOISE
5
- #test.warning = true
4
+ test.warning = true
6
5
  test.pattern = 'test/**/test_*.rb'
7
6
  end
8
7
 
9
8
  task :default => :test
9
+
10
+ task :appraise do
11
+ exec("cd myapp && rake appraise")
12
+ end
@@ -1,5 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # Quiet some warnings we see when running in warning mode:
4
+ # RUBYOPT=-w bundle exec sidekiq
5
+ $TESTING = false
6
+
3
7
  require_relative '../lib/sidekiq/cli'
4
8
 
5
9
  begin
@@ -3,16 +3,32 @@
3
3
  require 'fileutils'
4
4
 
5
5
  class Sidekiqctl
6
-
7
- attr_reader :stage, :pidfile, :timeout
6
+ DEFAULT_KILL_TIMEOUT = 10
7
+
8
+ attr_reader :stage, :pidfile, :kill_timeout
9
+
10
+ def self.print_usage
11
+ puts "#{File.basename($0)} - stop a Sidekiq process from the command line."
12
+ puts
13
+ puts "Usage: #{File.basename($0)} <command> <pidfile> <kill_timeout>"
14
+ puts " where <command> is either 'quiet' or 'stop'"
15
+ puts " <pidfile> is path to a pidfile"
16
+ puts " <kill_timeout> is number of seconds to wait until Sidekiq exits"
17
+ puts " (default: #{Sidekiqctl::DEFAULT_KILL_TIMEOUT}), after which Sidekiq will be KILL'd"
18
+ puts
19
+ puts "Be sure to set the kill_timeout LONGER than Sidekiq's -t timeout. If you want"
20
+ puts "to wait 60 seconds for jobs to finish, use `sidekiq -t 60` and `sidekiqctl stop"
21
+ puts " path_to_pidfile 61`"
22
+ puts
23
+ end
8
24
 
9
25
  def initialize(stage, pidfile, timeout)
10
26
  @stage = stage
11
27
  @pidfile = pidfile
12
- @timeout = timeout
28
+ @kill_timeout = timeout
13
29
 
14
30
  done('No pidfile given', :error) if !pidfile
15
- done("Pidfile #{pidfile} does not exist", :error) if !File.exist?(pidfile)
31
+ done("Pidfile #{pidfile} does not exist", :warn) if !File.exist?(pidfile)
16
32
  done('Invalid pidfile content', :error) if pid == 0
17
33
 
18
34
  fetch_process
@@ -20,14 +36,18 @@ class Sidekiqctl
20
36
  begin
21
37
  send(stage)
22
38
  rescue NoMethodError
23
- done 'Invalid control command', :error
39
+ done "Invalid command: #{stage}", :error
24
40
  end
25
41
  end
26
42
 
27
43
  def fetch_process
28
- Process.getpgid(pid)
44
+ Process.kill(0, pid)
29
45
  rescue Errno::ESRCH
30
46
  done "Process doesn't exist", :error
47
+ # We were not allowed to send a signal, but the process must have existed
48
+ # when Process.kill() was called.
49
+ rescue Errno::EPERM
50
+ return pid
31
51
  end
32
52
 
33
53
  def done(msg, error = nil)
@@ -40,7 +60,7 @@ class Sidekiqctl
40
60
  end
41
61
 
42
62
  def pid
43
- File.read(pidfile).to_i
63
+ @pid ||= File.read(pidfile).to_i
44
64
  end
45
65
 
46
66
  def quiet
@@ -49,12 +69,14 @@ class Sidekiqctl
49
69
 
50
70
  def stop
51
71
  `kill -TERM #{pid}`
52
- timeout.times do
72
+ kill_timeout.times do
53
73
  begin
54
- Process.getpgid(pid)
74
+ Process.kill(0, pid)
55
75
  rescue Errno::ESRCH
56
76
  FileUtils.rm_f pidfile
57
77
  done 'Sidekiq shut down gracefully.'
78
+ rescue Errno::EPERM
79
+ done 'Not permitted to shut down Sidekiq.'
58
80
  end
59
81
  sleep 1
60
82
  end
@@ -62,17 +84,16 @@ class Sidekiqctl
62
84
  FileUtils.rm_f pidfile
63
85
  done 'Sidekiq shut down forcefully.'
64
86
  end
65
-
66
- def shutdown
67
- quiet
68
- stop
69
- end
70
-
87
+ alias_method :shutdown, :stop
71
88
  end
72
89
 
73
- stage = ARGV[0]
74
- pidfile = ARGV[1]
75
- timeout = ARGV[2].to_i
76
- timeout = 10 if timeout == 0
90
+ if ARGV.length < 2
91
+ Sidekiqctl.print_usage
92
+ else
93
+ stage = ARGV[0]
94
+ pidfile = ARGV[1]
95
+ timeout = ARGV[2].to_i
96
+ timeout = Sidekiqctl::DEFAULT_KILL_TIMEOUT if timeout == 0
77
97
 
78
- Sidekiqctl.new(stage, pidfile, timeout)
98
+ Sidekiqctl.new(stage, pidfile, timeout)
99
+ end
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Quiet some warnings we see when running in warning mode:
4
+ # RUBYOPT=-w bundle exec sidekiq
5
+ $TESTING = false
6
+
7
+ #require 'ruby-prof'
8
+ Bundler.require(:default)
9
+
10
+ require_relative '../lib/sidekiq/cli'
11
+ require_relative '../lib/sidekiq/launcher'
12
+
13
+ include Sidekiq::Util
14
+
15
+ Sidekiq.configure_server do |config|
16
+ #config.options[:concurrency] = 1
17
+ config.redis = { db: 13 }
18
+ config.options[:queues] << 'default'
19
+ config.logger.level = Logger::ERROR
20
+ config.average_scheduled_poll_interval = 2
21
+ config.reliable! if defined?(Sidekiq::Pro)
22
+ end
23
+
24
+ class LoadWorker
25
+ include Sidekiq::Worker
26
+ sidekiq_options retry: 1
27
+ sidekiq_retry_in do |x|
28
+ 1
29
+ end
30
+
31
+ def perform(idx)
32
+ #raise idx.to_s if idx % 100 == 1
33
+ end
34
+ end
35
+
36
+ # brew tap shopify/shopify
37
+ # brew install toxiproxy
38
+ # gem install toxiproxy
39
+ #require 'toxiproxy'
40
+ # simulate a non-localhost network for realer-world conditions.
41
+ # adding 1ms of network latency has an ENORMOUS impact on benchmarks
42
+ #Toxiproxy.populate([{
43
+ #"name": "redis",
44
+ #"listen": "127.0.0.1:6380",
45
+ #"upstream": "127.0.0.1:6379"
46
+ #}])
47
+
48
+ self_read, self_write = IO.pipe
49
+ %w(INT TERM USR1 USR2 TTIN).each do |sig|
50
+ begin
51
+ trap sig do
52
+ self_write.puts(sig)
53
+ end
54
+ rescue ArgumentError
55
+ puts "Signal #{sig} not supported"
56
+ end
57
+ end
58
+
59
+ Sidekiq.redis {|c| c.flushdb}
60
+ def handle_signal(launcher, sig)
61
+ Sidekiq.logger.debug "Got #{sig} signal"
62
+ case sig
63
+ when 'INT'
64
+ # Handle Ctrl-C in JRuby like MRI
65
+ # http://jira.codehaus.org/browse/JRUBY-4637
66
+ raise Interrupt
67
+ when 'TERM'
68
+ # Heroku sends TERM and then waits 10 seconds for process to exit.
69
+ raise Interrupt
70
+ when 'USR1'
71
+ Sidekiq.logger.info "Received USR1, no longer accepting new work"
72
+ launcher.quiet
73
+ when 'USR2'
74
+ if Sidekiq.options[:logfile]
75
+ Sidekiq.logger.info "Received USR2, reopening log file"
76
+ Sidekiq::Logging.reopen_logs
77
+ end
78
+ when 'TTIN'
79
+ Thread.list.each do |thread|
80
+ Sidekiq.logger.warn "Thread TID-#{thread.object_id.to_s(36)} #{thread['label']}"
81
+ if thread.backtrace
82
+ Sidekiq.logger.warn thread.backtrace.join("\n")
83
+ else
84
+ Sidekiq.logger.warn "<no backtrace available>"
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ def Process.rss
91
+ `ps -o rss= -p #{Process.pid}`.chomp.to_i
92
+ end
93
+
94
+ iter = 10
95
+ count = 10_000
96
+
97
+ iter.times do
98
+ arr = Array.new(count) do
99
+ []
100
+ end
101
+ count.times do |idx|
102
+ arr[idx][0] = idx
103
+ end
104
+ Sidekiq::Client.push_bulk('class' => LoadWorker, 'args' => arr)
105
+ end
106
+ Sidekiq.logger.error "Created #{count*iter} jobs"
107
+
108
+ Monitoring = Thread.new do
109
+ watchdog("monitor thread") do
110
+ while true
111
+ sleep 1
112
+ qsize, retries = Sidekiq.redis do |conn|
113
+ conn.pipelined do
114
+ conn.llen "queue:default"
115
+ conn.zcard "retry"
116
+ end
117
+ end.map(&:to_i)
118
+ total = qsize + retries
119
+ #GC.start
120
+ Sidekiq.logger.error("RSS: #{Process.rss} Pending: #{total}")
121
+ if total == 0
122
+ Sidekiq.logger.error("Done")
123
+ exit(0)
124
+ end
125
+ end
126
+ end
127
+ end
128
+
129
+ begin
130
+ #RubyProf::exclude_threads = [ Monitoring ]
131
+ #RubyProf.start
132
+ fire_event(:startup)
133
+ #Sidekiq.logger.error "Simulating 1ms of latency between Sidekiq and redis"
134
+ #Toxiproxy[:redis].downstream(:latency, latency: 1).apply do
135
+ launcher = Sidekiq::Launcher.new(Sidekiq.options)
136
+ launcher.run
137
+
138
+ while readable_io = IO.select([self_read])
139
+ signal = readable_io.first[0].gets.strip
140
+ handle_signal(launcher, signal)
141
+ end
142
+ #end
143
+ rescue SystemExit => e
144
+ #Sidekiq.logger.error("Profiling...")
145
+ #result = RubyProf.stop
146
+ #printer = RubyProf::GraphHtmlPrinter.new(result)
147
+ #printer.print(File.new("output.html", "w"), :min_percent => 1)
148
+ # normal
149
+ rescue => e
150
+ raise e if $DEBUG
151
+ STDERR.puts e.message
152
+ STDERR.puts e.backtrace.join("\n")
153
+ exit 1
154
+ end
@@ -0,0 +1,50 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This Code of Conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting the project maintainer at mperham AT gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+
45
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
46
+ version 1.3.0, available at
47
+ [http://contributor-covenant.org/version/1/3/0/][version]
48
+
49
+ [homepage]: http://contributor-covenant.org
50
+ [version]: http://contributor-covenant.org/version/1/3/0/