sidekiq 0.10.0 → 7.2.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.

Files changed (234) hide show
  1. checksums.yaml +7 -0
  2. data/Changes.md +2082 -0
  3. data/LICENSE.txt +9 -0
  4. data/README.md +73 -27
  5. data/bin/sidekiq +25 -9
  6. data/bin/sidekiqload +247 -0
  7. data/bin/sidekiqmon +11 -0
  8. data/lib/generators/sidekiq/job_generator.rb +57 -0
  9. data/lib/generators/sidekiq/templates/job.rb.erb +9 -0
  10. data/lib/generators/sidekiq/templates/job_spec.rb.erb +6 -0
  11. data/lib/generators/sidekiq/templates/job_test.rb.erb +8 -0
  12. data/lib/sidekiq/api.rb +1145 -0
  13. data/lib/sidekiq/capsule.rb +127 -0
  14. data/lib/sidekiq/cli.rb +348 -109
  15. data/lib/sidekiq/client.rb +241 -41
  16. data/lib/sidekiq/component.rb +68 -0
  17. data/lib/sidekiq/config.rb +287 -0
  18. data/lib/sidekiq/deploy.rb +62 -0
  19. data/lib/sidekiq/embedded.rb +61 -0
  20. data/lib/sidekiq/fetch.rb +88 -0
  21. data/lib/sidekiq/job.rb +374 -0
  22. data/lib/sidekiq/job_logger.rb +51 -0
  23. data/lib/sidekiq/job_retry.rb +301 -0
  24. data/lib/sidekiq/job_util.rb +107 -0
  25. data/lib/sidekiq/launcher.rb +271 -0
  26. data/lib/sidekiq/logger.rb +131 -0
  27. data/lib/sidekiq/manager.rb +96 -103
  28. data/lib/sidekiq/metrics/query.rb +155 -0
  29. data/lib/sidekiq/metrics/shared.rb +95 -0
  30. data/lib/sidekiq/metrics/tracking.rb +136 -0
  31. data/lib/sidekiq/middleware/chain.rb +149 -38
  32. data/lib/sidekiq/middleware/current_attributes.rb +95 -0
  33. data/lib/sidekiq/middleware/i18n.rb +42 -0
  34. data/lib/sidekiq/middleware/modules.rb +21 -0
  35. data/lib/sidekiq/monitor.rb +146 -0
  36. data/lib/sidekiq/paginator.rb +55 -0
  37. data/lib/sidekiq/processor.rb +246 -61
  38. data/lib/sidekiq/rails.rb +60 -13
  39. data/lib/sidekiq/redis_client_adapter.rb +111 -0
  40. data/lib/sidekiq/redis_connection.rb +68 -15
  41. data/lib/sidekiq/ring_buffer.rb +29 -0
  42. data/lib/sidekiq/scheduled.rb +236 -0
  43. data/lib/sidekiq/sd_notify.rb +149 -0
  44. data/lib/sidekiq/systemd.rb +24 -0
  45. data/lib/sidekiq/testing/inline.rb +30 -0
  46. data/lib/sidekiq/testing.rb +310 -10
  47. data/lib/sidekiq/transaction_aware_client.rb +44 -0
  48. data/lib/sidekiq/version.rb +4 -1
  49. data/lib/sidekiq/web/action.rb +93 -0
  50. data/lib/sidekiq/web/application.rb +463 -0
  51. data/lib/sidekiq/web/csrf_protection.rb +180 -0
  52. data/lib/sidekiq/web/helpers.rb +364 -0
  53. data/lib/sidekiq/web/router.rb +104 -0
  54. data/lib/sidekiq/web.rb +143 -74
  55. data/lib/sidekiq/worker_compatibility_alias.rb +13 -0
  56. data/lib/sidekiq.rb +120 -73
  57. data/sidekiq.gemspec +26 -23
  58. data/web/assets/images/apple-touch-icon.png +0 -0
  59. data/web/assets/images/favicon.ico +0 -0
  60. data/web/assets/images/logo.png +0 -0
  61. data/web/assets/images/status.png +0 -0
  62. data/web/assets/javascripts/application.js +177 -3
  63. data/web/assets/javascripts/base-charts.js +106 -0
  64. data/web/assets/javascripts/chart.min.js +13 -0
  65. data/web/assets/javascripts/chartjs-plugin-annotation.min.js +7 -0
  66. data/web/assets/javascripts/dashboard-charts.js +182 -0
  67. data/web/assets/javascripts/dashboard.js +57 -0
  68. data/web/assets/javascripts/metrics.js +298 -0
  69. data/web/assets/stylesheets/application-dark.css +147 -0
  70. data/web/assets/stylesheets/application-rtl.css +153 -0
  71. data/web/assets/stylesheets/application.css +729 -7
  72. data/web/assets/stylesheets/bootstrap-rtl.min.css +9 -0
  73. data/web/assets/stylesheets/bootstrap.css +5 -0
  74. data/web/locales/ar.yml +87 -0
  75. data/web/locales/cs.yml +78 -0
  76. data/web/locales/da.yml +75 -0
  77. data/web/locales/de.yml +81 -0
  78. data/web/locales/el.yml +87 -0
  79. data/web/locales/en.yml +101 -0
  80. data/web/locales/es.yml +86 -0
  81. data/web/locales/fa.yml +80 -0
  82. data/web/locales/fr.yml +99 -0
  83. data/web/locales/gd.yml +99 -0
  84. data/web/locales/he.yml +80 -0
  85. data/web/locales/hi.yml +75 -0
  86. data/web/locales/it.yml +69 -0
  87. data/web/locales/ja.yml +91 -0
  88. data/web/locales/ko.yml +68 -0
  89. data/web/locales/lt.yml +83 -0
  90. data/web/locales/nb.yml +77 -0
  91. data/web/locales/nl.yml +68 -0
  92. data/web/locales/pl.yml +59 -0
  93. data/web/locales/pt-br.yml +96 -0
  94. data/web/locales/pt.yml +67 -0
  95. data/web/locales/ru.yml +83 -0
  96. data/web/locales/sv.yml +68 -0
  97. data/web/locales/ta.yml +75 -0
  98. data/web/locales/uk.yml +77 -0
  99. data/web/locales/ur.yml +80 -0
  100. data/web/locales/vi.yml +83 -0
  101. data/web/locales/zh-cn.yml +95 -0
  102. data/web/locales/zh-tw.yml +102 -0
  103. data/web/views/_footer.erb +23 -0
  104. data/web/views/_job_info.erb +105 -0
  105. data/web/views/_metrics_period_select.erb +12 -0
  106. data/web/views/_nav.erb +52 -0
  107. data/web/views/_paging.erb +25 -0
  108. data/web/views/_poll_link.erb +4 -0
  109. data/web/views/_status.erb +4 -0
  110. data/web/views/_summary.erb +40 -0
  111. data/web/views/busy.erb +148 -0
  112. data/web/views/dashboard.erb +105 -0
  113. data/web/views/dead.erb +34 -0
  114. data/web/views/filtering.erb +7 -0
  115. data/web/views/layout.erb +42 -0
  116. data/web/views/metrics.erb +91 -0
  117. data/web/views/metrics_for_job.erb +59 -0
  118. data/web/views/morgue.erb +74 -0
  119. data/web/views/queue.erb +55 -0
  120. data/web/views/queues.erb +44 -0
  121. data/web/views/retries.erb +79 -0
  122. data/web/views/retry.erb +34 -0
  123. data/web/views/scheduled.erb +56 -0
  124. data/web/views/scheduled_job_info.erb +8 -0
  125. metadata +159 -237
  126. data/.gitignore +0 -6
  127. data/.rvmrc +0 -4
  128. data/COMM-LICENSE +0 -75
  129. data/Gemfile +0 -10
  130. data/LICENSE +0 -22
  131. data/Rakefile +0 -9
  132. data/TODO.md +0 -1
  133. data/bin/client +0 -7
  134. data/bin/sidekiqctl +0 -43
  135. data/config.ru +0 -8
  136. data/examples/chef/cookbooks/sidekiq/README.rdoc +0 -11
  137. data/examples/chef/cookbooks/sidekiq/recipes/default.rb +0 -55
  138. data/examples/chef/cookbooks/sidekiq/templates/default/monitrc.conf.erb +0 -8
  139. data/examples/chef/cookbooks/sidekiq/templates/default/sidekiq.erb +0 -219
  140. data/examples/chef/cookbooks/sidekiq/templates/default/sidekiq.yml.erb +0 -22
  141. data/examples/config.yml +0 -9
  142. data/examples/monitrc.conf +0 -6
  143. data/examples/por.rb +0 -27
  144. data/examples/scheduling.rb +0 -37
  145. data/examples/sinkiq.rb +0 -57
  146. data/examples/web-ui.png +0 -0
  147. data/lib/sidekiq/capistrano.rb +0 -32
  148. data/lib/sidekiq/extensions/action_mailer.rb +0 -26
  149. data/lib/sidekiq/extensions/active_record.rb +0 -27
  150. data/lib/sidekiq/extensions/generic_proxy.rb +0 -21
  151. data/lib/sidekiq/middleware/client/unique_jobs.rb +0 -32
  152. data/lib/sidekiq/middleware/server/active_record.rb +0 -13
  153. data/lib/sidekiq/middleware/server/exception_handler.rb +0 -38
  154. data/lib/sidekiq/middleware/server/failure_jobs.rb +0 -24
  155. data/lib/sidekiq/middleware/server/logging.rb +0 -27
  156. data/lib/sidekiq/middleware/server/retry_jobs.rb +0 -59
  157. data/lib/sidekiq/middleware/server/unique_jobs.rb +0 -15
  158. data/lib/sidekiq/retry.rb +0 -57
  159. data/lib/sidekiq/util.rb +0 -61
  160. data/lib/sidekiq/worker.rb +0 -37
  161. data/myapp/.gitignore +0 -15
  162. data/myapp/Capfile +0 -5
  163. data/myapp/Gemfile +0 -19
  164. data/myapp/Gemfile.lock +0 -143
  165. data/myapp/Rakefile +0 -7
  166. data/myapp/app/controllers/application_controller.rb +0 -3
  167. data/myapp/app/controllers/work_controller.rb +0 -38
  168. data/myapp/app/helpers/application_helper.rb +0 -2
  169. data/myapp/app/mailers/.gitkeep +0 -0
  170. data/myapp/app/mailers/user_mailer.rb +0 -9
  171. data/myapp/app/models/.gitkeep +0 -0
  172. data/myapp/app/models/post.rb +0 -5
  173. data/myapp/app/views/layouts/application.html.erb +0 -14
  174. data/myapp/app/views/user_mailer/greetings.html.erb +0 -3
  175. data/myapp/app/views/work/index.html.erb +0 -1
  176. data/myapp/app/workers/hard_worker.rb +0 -9
  177. data/myapp/config/application.rb +0 -59
  178. data/myapp/config/boot.rb +0 -6
  179. data/myapp/config/database.yml +0 -25
  180. data/myapp/config/deploy.rb +0 -15
  181. data/myapp/config/environment.rb +0 -5
  182. data/myapp/config/environments/development.rb +0 -38
  183. data/myapp/config/environments/production.rb +0 -67
  184. data/myapp/config/environments/test.rb +0 -37
  185. data/myapp/config/initializers/backtrace_silencers.rb +0 -7
  186. data/myapp/config/initializers/inflections.rb +0 -15
  187. data/myapp/config/initializers/mime_types.rb +0 -5
  188. data/myapp/config/initializers/secret_token.rb +0 -7
  189. data/myapp/config/initializers/session_store.rb +0 -8
  190. data/myapp/config/initializers/sidekiq.rb +0 -6
  191. data/myapp/config/initializers/wrap_parameters.rb +0 -14
  192. data/myapp/config/locales/en.yml +0 -5
  193. data/myapp/config/routes.rb +0 -10
  194. data/myapp/config.ru +0 -4
  195. data/myapp/db/migrate/20120123214055_create_posts.rb +0 -10
  196. data/myapp/db/seeds.rb +0 -7
  197. data/myapp/lib/assets/.gitkeep +0 -0
  198. data/myapp/lib/tasks/.gitkeep +0 -0
  199. data/myapp/log/.gitkeep +0 -0
  200. data/myapp/script/rails +0 -6
  201. data/test/config.yml +0 -9
  202. data/test/fake_env.rb +0 -0
  203. data/test/helper.rb +0 -15
  204. data/test/test_cli.rb +0 -168
  205. data/test/test_client.rb +0 -105
  206. data/test/test_extensions.rb +0 -68
  207. data/test/test_manager.rb +0 -43
  208. data/test/test_middleware.rb +0 -92
  209. data/test/test_processor.rb +0 -32
  210. data/test/test_retry.rb +0 -83
  211. data/test/test_stats.rb +0 -78
  212. data/test/test_testing.rb +0 -65
  213. data/test/test_web.rb +0 -61
  214. data/web/assets/images/bootstrap/glyphicons-halflings-white.png +0 -0
  215. data/web/assets/images/bootstrap/glyphicons-halflings.png +0 -0
  216. data/web/assets/javascripts/vendor/bootstrap/bootstrap-alert.js +0 -91
  217. data/web/assets/javascripts/vendor/bootstrap/bootstrap-button.js +0 -98
  218. data/web/assets/javascripts/vendor/bootstrap/bootstrap-carousel.js +0 -154
  219. data/web/assets/javascripts/vendor/bootstrap/bootstrap-collapse.js +0 -136
  220. data/web/assets/javascripts/vendor/bootstrap/bootstrap-dropdown.js +0 -92
  221. data/web/assets/javascripts/vendor/bootstrap/bootstrap-modal.js +0 -210
  222. data/web/assets/javascripts/vendor/bootstrap/bootstrap-popover.js +0 -95
  223. data/web/assets/javascripts/vendor/bootstrap/bootstrap-scrollspy.js +0 -125
  224. data/web/assets/javascripts/vendor/bootstrap/bootstrap-tab.js +0 -130
  225. data/web/assets/javascripts/vendor/bootstrap/bootstrap-tooltip.js +0 -270
  226. data/web/assets/javascripts/vendor/bootstrap/bootstrap-transition.js +0 -51
  227. data/web/assets/javascripts/vendor/bootstrap/bootstrap-typeahead.js +0 -271
  228. data/web/assets/javascripts/vendor/bootstrap.js +0 -12
  229. data/web/assets/javascripts/vendor/jquery.js +0 -9266
  230. data/web/assets/stylesheets/vendor/bootstrap-responsive.css +0 -567
  231. data/web/assets/stylesheets/vendor/bootstrap.css +0 -3365
  232. data/web/views/index.slim +0 -62
  233. data/web/views/layout.slim +0 -24
  234. data/web/views/queue.slim +0 -11
data/bin/sidekiqctl DELETED
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'fileutils'
4
-
5
- stage = ARGV[0]
6
- pidfile = ARGV[1]
7
- timeout = ARGV[2].to_i
8
- timeout = 10 if timeout == 0
9
-
10
- def done(msg)
11
- puts msg
12
- exit(0)
13
- end
14
-
15
- done 'No pidfile given' if !pidfile
16
- done 'Pidfile does not exist' if !File.exist?(pidfile)
17
-
18
- pid = File.read(pidfile).to_i
19
- done 'Invalid pidfile content' if pid == 0
20
-
21
- begin
22
- Process.getpgid(pid)
23
- rescue Errno::ESRCH
24
- done "Process doesn't exist"
25
- end
26
-
27
- case stage
28
- when 'quiet'
29
- `kill -USR1 #{pid}`
30
- when 'stop'
31
- `kill -TERM #{pid}`
32
- timeout.times do
33
- begin
34
- Process.getpgid(pid)
35
- rescue Errno::ESRCH
36
- FileUtils.rm_f pidfile
37
- done 'Sidekiq shut down gracefully.'
38
- end
39
- sleep 1
40
- end
41
- `kill -9 #{pid}`
42
- done 'Sidekiq shut down forcefully.'
43
- end
data/config.ru DELETED
@@ -1,8 +0,0 @@
1
- require 'sidekiq'
2
-
3
- Sidekiq.configure_client do |config|
4
- config.redis = { :size => 1 }
5
- end
6
-
7
- require 'sidekiq/web'
8
- run Sidekiq::Web
@@ -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,219 +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
- SLEEP_COUNT=0
46
- kill -$SIG $PID
47
- fi
48
- }
49
-
50
- signal_worker_fatally(){
51
- signal_worker()
52
- if [ -f $PID_FILE ]; then
53
- if [ -n "$ALLOW_TIMEOUT" ]; then
54
- while [ -e /proc/$PID ]; do
55
- sleep .25
56
- let "SLEEP_COUNT+=1"
57
- let "REPORT_TIME = $SLEEP_COUNT%4"
58
- if(( "$SLEEP_COUNT" > $GRACE_TIME )); then
59
- logger -t "monit-sidekiq[$$]" "Sidekiq worker with pid $PID for $WORKER_REF still running, issuing -TERM"
60
- kill -15 $PID 2>/dev/null; true
61
- elif(( $REPORT_TIME == 0 )); then
62
- let "RUNTIME = $SLEEP_COUNT/4"
63
- logger -t "monit-sidekiq[$$]" "waiting for $PID to die ( for $RUNTIME seconds now)"
64
- fi
65
- done
66
- fi
67
- sleep 1
68
- if [ -d /proc/$PID ];then
69
- for child in $(ps axo pid,ppid | awk "{ if ( \$2 == $PID ) { print \$1 }}");
70
- do
71
- kill -9 $child 2>/dev/null; true
72
- logger -t "monit-sidekiq[$$]" "Murdering Sidekiq workers child with $child for $WORKER_REF"
73
- break
74
- done
75
- while [ -d /proc/$PID ]; do
76
- logger -t "monit-sidekiq[$$]" "Murdering Sidekiq worker with $PID for $WORKER_REF"
77
- kill -9 $PID
78
- sleep 1
79
- done
80
- fi
81
- logger -t "monit-sidekiq[$$]" "Removing pid file for $PID - $WORKER_REF"
82
- [ -e "$PID_FILE" -a ! -d /proc/$PID ] && rm -f $PID_FILE
83
- fi
84
- }
85
-
86
- lock(){
87
- RESULT=0
88
- if [ -e $LOCK_FILE ]; then
89
- LAST_LOCK_PID=`cat $LOCK_FILE`
90
- if [ -n $LAST_LOCK_PID -a -z "`ps axo pid|grep $LAST_LOCK_PID`" -a -f $LOCK_FILE ];then
91
- sleep 1
92
- logger -t "monit-sidekiq[$$]" "Removing stale lock file for $WORKER_REF ($LAST_LOCK_PID)"
93
- rm $LOCK_FILE 2>&1
94
- else
95
- logger -t "monit-sidekiq[$$]" "Monit already messing with $WORKER_REF ($LAST_LOCK_PID)"
96
- RESULT=1
97
- exit_cleanly
98
- fi
99
- fi
100
- echo $$ > $LOCK_FILE
101
- }
102
-
103
- legacy_fix() {
104
- #In the transition from 0.18.2 to 0.18.3 of ey monit scripts the way
105
- #the pid file is used to find the process to kill has changed.
106
- #To avert problems being left behind after an upgrade of this package,
107
- if [ -f $PID_FILE ]; then
108
- set_pid_from_file
109
- if [ -n "`ps axo pid,command|grep $PID|grep 'su -c'`" ];then
110
- logger -t "monit-sidekiq[$$]" "Monit Scripts have just been upgraded, killing old style workers"
111
- for child in $(ps axo pid,ppid| awk "{ if ( \$2 == $PID ) { print \$1 }}");
112
- do
113
- kill -TERM $child 2> /dev/null
114
- while [ -e /proc/$child ]; do
115
- logger -t "monit-sidekiq[$$]" "killing legacy worker: $child"
116
- [ -e /proc/$child ] && kill -9 $child 2> /dev/null
117
- sleep 1
118
- done
119
- done
120
- [ -e /proc/$PID ] && kill -9 $PID 2> /dev/null
121
- rm $PID_FILE
122
- unlock_exit_cleanly
123
- fi
124
- fi
125
- }
126
-
127
- if [ $# -lt 4 ]; then usage; fi
128
-
129
- if [ "`whoami`" != "root" ]; then
130
- logger -t `basename $0` -s "Must be run as root"
131
- exit 1
132
- fi
133
-
134
- #Baisc Setup of default values
135
- APP=$1 ; ACTION=$2; RACK_ENV=$3; CONF_FILE=$4;
136
-
137
- APP_DIR="/data/${APP}"
138
- APP_ROOT="${APP_DIR}/current"
139
- APP_SHARED="${APP_DIR}/shared"
140
- APP_CONFIG="${APP_SHARED}/config"
141
-
142
- if [ -e "${APP_CONFIG}/${CONF_FILE}" ]; then
143
- logger -t "sidekiq_${APP}" -s "Good, found a conf file. Proceeding..."
144
- else
145
- logger -t "sidekiq_${APP}" -s "/data/${APP}/shared/config/${CONF_FILE} not found for app: ${APP}"
146
- exit 1
147
- fi
148
-
149
- WORKER_REF=`echo $CONF_FILE | sed s/.conf//`
150
- LOG_FILE="$APP_ROOT/log/$WORKER_REF.log"
151
- LOCK_FILE="/tmp/$WORKER_REF.monit-lock"
152
- PID_FILE="/var/run/engineyard/sidekiq/$APP/$WORKER_REF.pid"
153
- GEMFILE="$APP_ROOT/Gemfile"
154
- SIDEKIQ="sidekiq"
155
- if [ -f $GEMFILE ];then
156
- SIDEKIQ="bundle exec $APP_ROOT/ey_bundler_binstubs/sidekiq"
157
- fi
158
-
159
- if [ -d $APP_ROOT ]; then
160
- USER=$(stat -L -c"%U" $APP_ROOT)
161
- export HOME="/home/$USER"
162
-
163
- # Fix for SD-3786 - stop sending in VERBOSE= and VVERBOSE= by default
164
- if declare -p VERBOSE >/dev/null 2>&1; then export V="VERBOSE=$VERBOSE"; fi
165
- if declare -p VVERBOSE >/dev/null 2>&1; then export VV="VVERBOSE=$VVERBOSE"; fi
166
-
167
- # Older versions of sudo need us to call env for the env vars to be set correctly
168
- 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}"
169
-
170
- if [ ! -d /var/run/engineyard/sidekiq/$APP ]; then
171
- mkdir -p /var/run/engineyard/sidekiq/$APP
172
- fi
173
-
174
- # handle the second param, don't start if already existing
175
-
176
- logger -t "monit-sidekiq[$$]" "${ACTION}ing Sidekiq worker $WORKER_REF"
177
- case "$ACTION" in
178
- start)
179
- lock
180
- cd $APP_ROOT
181
- if [ -f $PID_FILE ]; then
182
- set_pid_from_file
183
- if [ -d /proc/$PID ]; then
184
- logger -t "monit-sidekiq[$$]" "Sidekiq worker $WORKER_REF is already running with $PID."
185
- RESULT=1
186
- else
187
- rm -f $PID_FILE
188
- logger -t "monit-sidekiq[$$]" "Removing stale pid file ($PID_FILE) for pid $PID"
189
- fi
190
- fi
191
- if [ ! -f $PID_FILE ]; then
192
- sudo -u $USER -H $COMMAND >> $LOG_FILE 2>&1 &
193
- RESULT=$?
194
- logger -t "monit-sidekiq[$$]" "Started with pid $! and exit $RESULT"
195
- echo $! > $PID_FILE
196
- sleep .1
197
- fi
198
- unlock_and_exit_cleanly
199
- ;;
200
- stop|quit)
201
- legacy_fix
202
- lock
203
- SIG="INT"
204
- [ -z "$GRACE_TIME" ] && GRACE_TIME=60
205
- ALLOW_TIMEOUT=1
206
- signal_worker
207
- [ -e "$LOCK_FILE" ] && rm $LOCK_FILE
208
- unlock_and_exit_cleanly
209
- ;;
210
- *)
211
- usage
212
- exit_cleanly
213
- ;;
214
- esac
215
- else
216
- echo "/data/$APP/current doesn't exist."
217
- usage
218
- fi
219
-
@@ -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 %>
data/examples/config.yml DELETED
@@ -1,9 +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
- :concurrency: 25
7
- :queues:
8
- - [often, 2]
9
- - [seldom, 1]
@@ -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
data/examples/por.rb DELETED
@@ -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 = Sidekiq::RedisConnection.create(: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 = Sidekiq::RedisConnection.create(: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,37 +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 '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
data/examples/sinkiq.rb DELETED
@@ -1,57 +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/worker'
9
- $redis = Sidekiq::RedisConnection.create
10
-
11
- class SinatraWorker
12
- include Sidekiq::Worker
13
-
14
- def perform(msg="lulz you forgot a msg!")
15
- $redis.lpush("sinkiq-example-messages", msg)
16
- end
17
- end
18
-
19
- get '/' do
20
- @failed = $redis.get('stat:failed')
21
- @processed = $redis.get('stat:processed')
22
- @messages = $redis.lrange('sinkiq-example-messages', 0, -1)
23
- erb :index
24
- end
25
-
26
- post '/msg' do
27
- SinatraWorker.perform_async params[:msg]
28
- redirect to('/')
29
- end
30
-
31
- __END__
32
-
33
- @@ layout
34
- <html>
35
- <head>
36
- <title>Sinatra + Sidekiq</title>
37
- <body>
38
- <%= yield %>
39
- </body>
40
- </html>
41
-
42
- @@ index
43
- <h1>Sinata + Sidekiq Example</h1>
44
- <h2>Failed: <%= @failed %></h2>
45
- <h2>Processed: <%= @processed %></h2>
46
-
47
- <form method="post" action="/msg">
48
- <input type="text" name="msg">
49
- <input type="submit" value="Add Message">
50
- </form>
51
-
52
- <a href="/">Refresh page</a>
53
-
54
- <h3>Messages</h3>
55
- <% @messages.each do |msg| %>
56
- <p><%= msg %></p>
57
- <% end %>
data/examples/web-ui.png DELETED
Binary file
@@ -1,32 +0,0 @@
1
- Capistrano::Configuration.instance.load do
2
- before "deploy", "sidekiq:quiet"
3
- after "deploy", "sidekiq:restart"
4
-
5
- _cset(:sidekiq_timeout) { 10 }
6
-
7
- namespace :sidekiq do
8
-
9
- desc "Quiet sidekiq (stop accepting new work)"
10
- task :quiet do
11
- run "cd #{current_path} && sidekiqctl quiet #{current_path}/tmp/pids/sidekiq.pid"
12
- end
13
-
14
- desc "Stop sidekiq"
15
- task :stop do
16
- run "cd #{current_path} && sidekiqctl stop #{current_path}/tmp/pids/sidekiq.pid #{fetch :sidekiq_timeout}"
17
- end
18
-
19
- desc "Start sidekiq"
20
- task :start do
21
- rails_env = fetch(:rails_env, "production")
22
- run "cd #{current_path} && nohup bundle exec sidekiq -e #{rails_env} -C #{current_path}/config/sidekiq.yml -P #{current_path}/tmp/pids/sidekiq.pid >> #{current_path}/log/sidekiq.log 2>&1 &"
23
- end
24
-
25
- desc "Restart sidekiq"
26
- task :restart do
27
- stop
28
- start
29
- end
30
-
31
- end
32
- end
@@ -1,26 +0,0 @@
1
- require 'sidekiq/extensions/generic_proxy'
2
-
3
- module Sidekiq
4
- module Extensions
5
- ##
6
- # Adds a 'delay' method to ActionMailer to offload arbitrary email
7
- # delivery to Sidekiq. Example:
8
- #
9
- # UserMailer.delay.send_welcome_email(new_user)
10
- class DelayedMailer
11
- include Sidekiq::Worker
12
-
13
- def perform(yml)
14
- (target, method_name, args) = YAML.load(yml)
15
- target.send(method_name, *args).deliver
16
- end
17
- end
18
-
19
- module ActionMailer
20
- def delay
21
- Proxy.new(DelayedMailer, self)
22
- end
23
- end
24
-
25
- end
26
- end
@@ -1,27 +0,0 @@
1
- require 'sidekiq/extensions/generic_proxy'
2
-
3
- module Sidekiq
4
- module Extensions
5
- ##
6
- # Adds a 'delay' method to ActiveRecord to offload arbitrary method
7
- # execution to Sidekiq. Examples:
8
- #
9
- # User.delay.delete_inactive
10
- # User.recent_signups.each { |user| user.delay.mark_as_awesome }
11
- class DelayedModel
12
- include Sidekiq::Worker
13
-
14
- def perform(yml)
15
- (target, method_name, args) = YAML.load(yml)
16
- target.send(method_name, *args)
17
- end
18
- end
19
-
20
- module ActiveRecord
21
- def delay
22
- Proxy.new(DelayedModel, self)
23
- end
24
- end
25
-
26
- end
27
- end
@@ -1,21 +0,0 @@
1
- module Sidekiq
2
- module Extensions
3
- class Proxy < ::BasicObject
4
- def initialize(performable, target)
5
- @performable = performable
6
- @target = target
7
- end
8
-
9
- def method_missing(name, *args)
10
- # Sidekiq has a limitation in that its message must be JSON.
11
- # JSON can't round trip real Ruby objects so we use YAML to
12
- # serialize the objects to a String. The YAML will be converted
13
- # to JSON and then deserialized on the other side back into a
14
- # Ruby object.
15
- obj = [@target, name, args]
16
- @performable.perform_async(::YAML.dump(obj))
17
- end
18
- end
19
-
20
- end
21
- end
@@ -1,32 +0,0 @@
1
- require 'multi_json'
2
- require 'digest'
3
-
4
- module Sidekiq
5
- module Middleware
6
- module Client
7
- class UniqueJobs
8
- HASH_KEY_EXPIRATION = 30 * 60
9
-
10
- def call(item, queue)
11
- payload_hash = Digest::MD5.hexdigest(MultiJson.encode(item))
12
- unique = false
13
-
14
- Sidekiq.redis do |conn|
15
- conn.watch(payload_hash)
16
-
17
- if conn.get(payload_hash)
18
- conn.unwatch
19
- else
20
- unique = conn.multi do
21
- conn.setex(payload_hash, HASH_KEY_EXPIRATION, 1)
22
- end
23
- end
24
- end
25
-
26
- yield if unique
27
- end
28
-
29
- end
30
- end
31
- end
32
- end
@@ -1,13 +0,0 @@
1
- module Sidekiq
2
- module Middleware
3
- module Server
4
- class ActiveRecord
5
- def call(*args)
6
- yield
7
- ensure
8
- ::ActiveRecord::Base.clear_active_connections! if defined?(::ActiveRecord)
9
- end
10
- end
11
- end
12
- end
13
- end