kulesa-sidekiq 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rvmrc +4 -0
- data/COMM-LICENSE +83 -0
- data/Changes.md +207 -0
- data/Gemfile +12 -0
- data/LICENSE +22 -0
- data/README.md +61 -0
- data/Rakefile +9 -0
- data/bin/client +7 -0
- data/bin/sidekiq +14 -0
- data/bin/sidekiqctl +74 -0
- data/config.ru +18 -0
- data/examples/chef/cookbooks/sidekiq/README.rdoc +11 -0
- data/examples/chef/cookbooks/sidekiq/recipes/default.rb +55 -0
- data/examples/chef/cookbooks/sidekiq/templates/default/monitrc.conf.erb +8 -0
- data/examples/chef/cookbooks/sidekiq/templates/default/sidekiq.erb +219 -0
- data/examples/chef/cookbooks/sidekiq/templates/default/sidekiq.yml.erb +22 -0
- data/examples/clockwork.rb +44 -0
- data/examples/config.yml +10 -0
- data/examples/monitrc.conf +6 -0
- data/examples/por.rb +27 -0
- data/examples/scheduling.rb +37 -0
- data/examples/sinkiq.rb +59 -0
- data/examples/web-ui.png +0 -0
- data/lib/sidekiq.rb +98 -0
- data/lib/sidekiq/capistrano.rb +35 -0
- data/lib/sidekiq/cli.rb +214 -0
- data/lib/sidekiq/client.rb +72 -0
- data/lib/sidekiq/extensions/action_mailer.rb +26 -0
- data/lib/sidekiq/extensions/active_record.rb +27 -0
- data/lib/sidekiq/extensions/generic_proxy.rb +21 -0
- data/lib/sidekiq/fetch.rb +76 -0
- data/lib/sidekiq/logging.rb +46 -0
- data/lib/sidekiq/manager.rb +163 -0
- data/lib/sidekiq/middleware/chain.rb +96 -0
- data/lib/sidekiq/middleware/client/unique_jobs.rb +36 -0
- data/lib/sidekiq/middleware/server/active_record.rb +13 -0
- data/lib/sidekiq/middleware/server/exception_handler.rb +38 -0
- data/lib/sidekiq/middleware/server/failure_jobs.rb +25 -0
- data/lib/sidekiq/middleware/server/logging.rb +31 -0
- data/lib/sidekiq/middleware/server/retry_jobs.rb +69 -0
- data/lib/sidekiq/middleware/server/timeout.rb +21 -0
- data/lib/sidekiq/middleware/server/unique_jobs.rb +17 -0
- data/lib/sidekiq/processor.rb +92 -0
- data/lib/sidekiq/rails.rb +21 -0
- data/lib/sidekiq/redis_connection.rb +27 -0
- data/lib/sidekiq/retry.rb +59 -0
- data/lib/sidekiq/testing.rb +44 -0
- data/lib/sidekiq/testing/inline.rb +37 -0
- data/lib/sidekiq/util.rb +40 -0
- data/lib/sidekiq/version.rb +3 -0
- data/lib/sidekiq/web.rb +185 -0
- data/lib/sidekiq/worker.rb +62 -0
- data/lib/sidekiq/yaml_patch.rb +21 -0
- data/myapp/.gitignore +15 -0
- data/myapp/Capfile +5 -0
- data/myapp/Gemfile +19 -0
- data/myapp/Rakefile +7 -0
- data/myapp/app/controllers/application_controller.rb +3 -0
- data/myapp/app/controllers/work_controller.rb +38 -0
- data/myapp/app/helpers/application_helper.rb +2 -0
- data/myapp/app/mailers/.gitkeep +0 -0
- data/myapp/app/mailers/user_mailer.rb +9 -0
- data/myapp/app/models/.gitkeep +0 -0
- data/myapp/app/models/post.rb +5 -0
- data/myapp/app/views/layouts/application.html.erb +14 -0
- data/myapp/app/views/user_mailer/greetings.html.erb +3 -0
- data/myapp/app/views/work/index.html.erb +1 -0
- data/myapp/app/workers/hard_worker.rb +10 -0
- data/myapp/config.ru +4 -0
- data/myapp/config/application.rb +59 -0
- data/myapp/config/boot.rb +6 -0
- data/myapp/config/database.yml +25 -0
- data/myapp/config/deploy.rb +15 -0
- data/myapp/config/environment.rb +5 -0
- data/myapp/config/environments/development.rb +38 -0
- data/myapp/config/environments/production.rb +67 -0
- data/myapp/config/environments/test.rb +37 -0
- data/myapp/config/initializers/backtrace_silencers.rb +7 -0
- data/myapp/config/initializers/inflections.rb +15 -0
- data/myapp/config/initializers/mime_types.rb +5 -0
- data/myapp/config/initializers/secret_token.rb +7 -0
- data/myapp/config/initializers/session_store.rb +8 -0
- data/myapp/config/initializers/sidekiq.rb +6 -0
- data/myapp/config/initializers/wrap_parameters.rb +14 -0
- data/myapp/config/locales/en.yml +5 -0
- data/myapp/config/routes.rb +10 -0
- data/myapp/db/migrate/20120123214055_create_posts.rb +10 -0
- data/myapp/db/seeds.rb +7 -0
- data/myapp/lib/assets/.gitkeep +0 -0
- data/myapp/lib/tasks/.gitkeep +0 -0
- data/myapp/log/.gitkeep +0 -0
- data/myapp/script/rails +6 -0
- data/sidekiq.gemspec +27 -0
- data/test/config.yml +9 -0
- data/test/fake_env.rb +0 -0
- data/test/helper.rb +16 -0
- data/test/test_cli.rb +168 -0
- data/test/test_client.rb +119 -0
- data/test/test_extensions.rb +69 -0
- data/test/test_manager.rb +51 -0
- data/test/test_middleware.rb +92 -0
- data/test/test_processor.rb +32 -0
- data/test/test_retry.rb +125 -0
- data/test/test_stats.rb +68 -0
- data/test/test_testing.rb +97 -0
- data/test/test_testing_inline.rb +75 -0
- data/test/test_web.rb +122 -0
- data/web/assets/images/bootstrap/glyphicons-halflings-white.png +0 -0
- data/web/assets/images/bootstrap/glyphicons-halflings.png +0 -0
- data/web/assets/javascripts/application.js +20 -0
- data/web/assets/javascripts/vendor/bootstrap.js +12 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-alert.js +91 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-button.js +98 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-carousel.js +154 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-collapse.js +136 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-dropdown.js +92 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-modal.js +210 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-popover.js +95 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-scrollspy.js +125 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-tab.js +130 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-tooltip.js +270 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-transition.js +51 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-typeahead.js +271 -0
- data/web/assets/javascripts/vendor/jquery.js +9266 -0
- data/web/assets/javascripts/vendor/jquery.timeago.js +148 -0
- data/web/assets/stylesheets/application.css +27 -0
- data/web/assets/stylesheets/vendor/bootstrap-responsive.css +567 -0
- data/web/assets/stylesheets/vendor/bootstrap.css +3365 -0
- data/web/views/index.slim +48 -0
- data/web/views/layout.slim +26 -0
- data/web/views/queue.slim +11 -0
- data/web/views/retries.slim +29 -0
- data/web/views/retry.slim +52 -0
- metadata +371 -0
data/config.ru
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'sidekiq'
|
2
|
+
|
3
|
+
Sidekiq.configure_client do |config|
|
4
|
+
config.redis = { :size => 1 }
|
5
|
+
end
|
6
|
+
|
7
|
+
#Sidekiq.redis {|conn| conn.flushdb }
|
8
|
+
#10.times do |idx|
|
9
|
+
#Sidekiq::Client.push('class' => 'HardWorker', 'args' => ['foo', 0.1, idx])
|
10
|
+
#end
|
11
|
+
|
12
|
+
#Sidekiq.redis { |conn| conn.zadd('retry', Time.now.utc.to_f + 3000, MultiJson.encode({
|
13
|
+
#'class' => 'HardWorker', 'args' => ['foo', 0.1, Time.now.to_f],
|
14
|
+
#'queue' => 'default', 'error_message' => 'No such method', 'error_class' => 'NoMethodError',
|
15
|
+
#'failed_at' => Time.now.utc, 'retry_count' => 0 })) }
|
16
|
+
|
17
|
+
require 'sidekiq/web'
|
18
|
+
run Sidekiq::Web
|
@@ -0,0 +1,11 @@
|
|
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.
|
@@ -0,0 +1,55 @@
|
|
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
|
@@ -0,0 +1,8 @@
|
|
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 %>
|
@@ -0,0 +1,219 @@
|
|
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
|
+
|
@@ -0,0 +1,22 @@
|
|
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 %>
|
@@ -0,0 +1,44 @@
|
|
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
|
+
|
data/examples/config.yml
ADDED
@@ -0,0 +1,6 @@
|
|
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
ADDED
@@ -0,0 +1,27 @@
|
|
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
|
@@ -0,0 +1,37 @@
|
|
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
|