capistrano-resque 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +8 -1
- data/README.md +7 -5
- data/lib/capistrano-resque/capistrano_integration.rb +19 -9
- data/lib/capistrano-resque/tasks/capistrano-resque.rake +19 -8
- data/lib/capistrano-resque/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b898f69f6ed18119548b8e823a1e4256a05bacf
|
4
|
+
data.tar.gz: a3125435d75fa17c2178bde81ea35d744ee9a028
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0feb02dd81e7a47541af2b2af9b562278938b95ff40fd83a99de26ff85a9b40e6705cce6fb537b9b9eddbee7163033cd3f04229f8ecf72d129bcb6380a791429
|
7
|
+
data.tar.gz: 8481eeb7d14e711bcac8c218a0c736ea8e706c8d8a929c30291a829742b5f7daa8513a3a87e3acac36192a20b232c81e4ec2aaa9f08ee77f50b3ff70a04034c6
|
data/Changelog.md
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
-
#
|
1
|
+
# 0.2.1
|
2
|
+
* Create the directory for pid files when it doesn't exist
|
3
|
+
* Default pid files to `#{shared_path}/tmp/pids` now
|
4
|
+
* Added a `:resque_pid_path` option to specify a custom path
|
5
|
+
|
6
|
+
# 0.2.0
|
2
7
|
* Added support for Capistrano 3.0
|
3
8
|
* Set MUTE environment variable for resque_scheduler
|
4
9
|
* Added a `resque_environment_task` option to load the `environment` rake task before running Resque workers
|
5
10
|
* Add a resque:scheduler:status task
|
11
|
+
* Detect stale PID files and clean up instead of aborting
|
12
|
+
* Add a `resque_rails_env` setting in case workers need to be run in a different environment than the app itself
|
6
13
|
|
7
14
|
# 0.1.0
|
8
15
|
* Interval is configurable
|
data/README.md
CHANGED
@@ -27,9 +27,10 @@ role :resque_scheduler, "app_domain"
|
|
27
27
|
|
28
28
|
set :workers, { "my_queue_name" => 2 }
|
29
29
|
|
30
|
-
#
|
31
|
-
# sure to
|
32
|
-
|
30
|
+
# We default to storing PID files in a tmp/pids folder in your shared path, but
|
31
|
+
# you can customize it here (make sure to use a full path). The path will be
|
32
|
+
# created before starting workers if it doesn't already exist.
|
33
|
+
# set :resque_pid_path, -> { File.join(shared_path, 'tmp', 'pids') }
|
33
34
|
|
34
35
|
# Uncomment this line if your workers need access to the Rails environment:
|
35
36
|
# set :resque_environment_task, true
|
@@ -158,8 +159,9 @@ To to use more workers, please change your sshd configuration (/etc/ssh/sshd_con
|
|
158
159
|
1. Fork it
|
159
160
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
160
161
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
161
|
-
4.
|
162
|
-
5.
|
162
|
+
4. If possible, make sure your changes apply to both the Capistrano v2 and v3 code (`capistrano_integration.rb` is v2, `capistrano-resque.rake` is v3)
|
163
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
164
|
+
6. Create new Pull Request
|
163
165
|
|
164
166
|
### License
|
165
167
|
|
@@ -11,6 +11,7 @@ module CapistranoResque
|
|
11
11
|
_cset(:interval, "5")
|
12
12
|
_cset(:resque_environment_task, false)
|
13
13
|
_cset(:resque_log_file, "/dev/null")
|
14
|
+
_cset(:resque_pid_path) { File.join(shared_path, 'tmp', 'pids') }
|
14
15
|
|
15
16
|
def rails_env
|
16
17
|
fetch(:resque_rails_env, fetch(:rails_env, "production"))
|
@@ -36,8 +37,8 @@ module CapistranoResque
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def status_command
|
39
|
-
"if [ -e #{
|
40
|
-
for f in $(ls #{
|
40
|
+
"if [ -e #{fetch(:resque_pid_path)}/resque_work_1.pid ]; then \
|
41
|
+
for f in $(ls #{fetch(:resque_pid_path)}/resque_work*.pid); \
|
41
42
|
do ps -p $(cat $f) | sed -n 2p ; done \
|
42
43
|
;fi"
|
43
44
|
end
|
@@ -51,8 +52,8 @@ module CapistranoResque
|
|
51
52
|
end
|
52
53
|
|
53
54
|
def stop_command
|
54
|
-
"if [ -e #{
|
55
|
-
for f in `ls #{
|
55
|
+
"if [ -e #{fetch(:resque_pid_path)}/resque_work_1.pid ]; then \
|
56
|
+
for f in `ls #{fetch(:resque_pid_path)}/resque_work*.pid`; \
|
56
57
|
do \
|
57
58
|
if kill -0 `cat $f`> /dev/null 2>&1; then \
|
58
59
|
kill -s #{resque_kill_signal} `cat $f` \
|
@@ -66,8 +67,8 @@ module CapistranoResque
|
|
66
67
|
end
|
67
68
|
|
68
69
|
def status_scheduler
|
69
|
-
"if [ -e #{
|
70
|
-
ps -p $(cat #{
|
70
|
+
"if [ -e #{fetch(:resque_pid_path)}/scheduler.pid ]; then \
|
71
|
+
ps -p $(cat #{fetch(:resque_pid_path)}/scheduler.pid) | sed -n 2p \
|
71
72
|
;fi"
|
72
73
|
end
|
73
74
|
|
@@ -83,6 +84,13 @@ module CapistranoResque
|
|
83
84
|
;fi"
|
84
85
|
end
|
85
86
|
|
87
|
+
def create_pid_path
|
88
|
+
"if [ ! -d #{fetch(:resque_pid_path)} ]; then \
|
89
|
+
echo 'Creating #{fetch(:resque_pid_path)}' \
|
90
|
+
&& mkdir -p #{fetch(:resque_pid_path)}\
|
91
|
+
;fi"
|
92
|
+
end
|
93
|
+
|
86
94
|
namespace :resque do
|
87
95
|
desc "See current worker status"
|
88
96
|
task :status, :roles => lambda { workers_roles() }, :on_no_matching_servers => :continue do
|
@@ -91,13 +99,14 @@ module CapistranoResque
|
|
91
99
|
|
92
100
|
desc "Start Resque workers"
|
93
101
|
task :start, :roles => lambda { workers_roles() }, :on_no_matching_servers => :continue do
|
102
|
+
run(create_pid_path)
|
94
103
|
for_each_workers do |role, workers|
|
95
104
|
worker_id = 1
|
96
105
|
workers.each_pair do |queue, number_of_workers|
|
97
106
|
logger.info "Starting #{number_of_workers} worker(s) with QUEUE: #{queue}"
|
98
107
|
threads = []
|
99
108
|
number_of_workers.times do
|
100
|
-
pid = "
|
109
|
+
pid = "#{fetch(:resque_pid_path)}/resque_work_#{worker_id}.pid"
|
101
110
|
threads << Thread.new(pid) { |pid| run(start_command(queue, pid), :roles => role) }
|
102
111
|
worker_id += 1
|
103
112
|
end
|
@@ -131,13 +140,14 @@ module CapistranoResque
|
|
131
140
|
|
132
141
|
desc "Starts resque scheduler with default configs"
|
133
142
|
task :start, :roles => :resque_scheduler do
|
134
|
-
|
143
|
+
run(create_pid_path)
|
144
|
+
pid = "#{fetch(:resque_pid_path)}/scheduler.pid"
|
135
145
|
run(start_scheduler(pid))
|
136
146
|
end
|
137
147
|
|
138
148
|
desc "Stops resque scheduler"
|
139
149
|
task :stop, :roles => :resque_scheduler do
|
140
|
-
pid = "#{
|
150
|
+
pid = "#{fetch(:resque_pid_path)}/scheduler.pid"
|
141
151
|
run(stop_scheduler(pid))
|
142
152
|
end
|
143
153
|
|
@@ -5,6 +5,7 @@ namespace :load do
|
|
5
5
|
set :interval, "5"
|
6
6
|
set :resque_environment_task, false
|
7
7
|
set :resque_log_file, "/dev/null"
|
8
|
+
set :resque_pid_path, -> { File.join(shared_path, 'tmp', 'pids') }
|
8
9
|
end
|
9
10
|
end
|
10
11
|
|
@@ -34,12 +35,19 @@ namespace :resque do
|
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
38
|
+
def create_pid_path
|
39
|
+
if !(test "[ -d #{fetch(:resque_pid_path)} ]")
|
40
|
+
info "Creating #{fetch(:resque_pid_path)}"
|
41
|
+
execute :mkdir, "-p #{fetch(:resque_pid_path)}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
37
45
|
desc "See current worker status"
|
38
46
|
task :status do
|
39
47
|
on roles(*workers_roles) do
|
40
|
-
if test "[ -e #{
|
48
|
+
if test "[ -e #{fetch(:resque_pid_path)}/resque_work_1.pid ]"
|
41
49
|
within current_path do
|
42
|
-
files = capture(:ls, "-1
|
50
|
+
files = capture(:ls, "-1 #{fetch(:resque_pid_path)}/resque_work*.pid")
|
43
51
|
files.each_line do |file|
|
44
52
|
info capture(:ps, "-f -p $(cat #{file.chomp}) | sed -n 2p")
|
45
53
|
end
|
@@ -50,13 +58,15 @@ namespace :resque do
|
|
50
58
|
|
51
59
|
desc "Start Resque workers"
|
52
60
|
task :start do
|
61
|
+
|
53
62
|
for_each_workers do |role, workers|
|
54
63
|
on roles(role) do
|
64
|
+
create_pid_path
|
55
65
|
worker_id = 1
|
56
66
|
workers.each_pair do |queue, number_of_workers|
|
57
67
|
info "Starting #{number_of_workers} worker(s) with QUEUE: #{queue}"
|
58
68
|
number_of_workers.times do
|
59
|
-
pid = "
|
69
|
+
pid = "#{fetch(:resque_pid_path)}/resque_work_#{worker_id}.pid"
|
60
70
|
within current_path do
|
61
71
|
execute :rake, %{RAILS_ENV=#{rails_env} QUEUE="#{queue}" PIDFILE=#{pid} BACKGROUND=yes VERBOSE=1 INTERVAL=#{fetch(:interval)} #{"environment" if fetch(:resque_environment_task)} resque:work #{output_redirection}}
|
62
72
|
end
|
@@ -76,9 +86,9 @@ namespace :resque do
|
|
76
86
|
desc "Quit running Resque workers"
|
77
87
|
task :stop do
|
78
88
|
on roles(*workers_roles) do
|
79
|
-
if test "[ -e #{
|
89
|
+
if test "[ -e #{fetch(:resque_pid_path)}/resque_work_1.pid ]"
|
80
90
|
within current_path do
|
81
|
-
pids = capture(:ls, "-1
|
91
|
+
pids = capture(:ls, "-1 #{fetch(:resque_pid_path)}/resque_work*.pid").lines.map(&:chomp)
|
82
92
|
pids.each do |pid_file|
|
83
93
|
pid = capture(:cat, pid_file)
|
84
94
|
if test "kill -0 #{pid} > /dev/null 2>&1"
|
@@ -105,7 +115,7 @@ namespace :resque do
|
|
105
115
|
desc "See current scheduler status"
|
106
116
|
task :status do
|
107
117
|
on roles :resque_scheduler do
|
108
|
-
pid = "#{
|
118
|
+
pid = "#{fetch(:resque_pid_path)}/scheduler.pid"
|
109
119
|
if test "[ -e #{pid} ]"
|
110
120
|
info capture(:ps, "-f -p $(cat #{pid}) | sed -n 2p")
|
111
121
|
end
|
@@ -115,7 +125,8 @@ namespace :resque do
|
|
115
125
|
desc "Starts resque scheduler with default configs"
|
116
126
|
task :start do
|
117
127
|
on roles :resque_scheduler do
|
118
|
-
|
128
|
+
create_pid_path
|
129
|
+
pid = "#{fetch(:resque_pid_path)}/scheduler.pid"
|
119
130
|
within current_path do
|
120
131
|
execute :rake, %{RAILS_ENV=#{rails_env} PIDFILE=#{pid} BACKGROUND=yes VERBOSE=1 MUTE=1 resque:scheduler #{output_redirection}}
|
121
132
|
end
|
@@ -125,7 +136,7 @@ namespace :resque do
|
|
125
136
|
desc "Stops resque scheduler"
|
126
137
|
task :stop do
|
127
138
|
on roles :resque_scheduler do
|
128
|
-
pid = "#{
|
139
|
+
pid = "#{fetch(:resque_pid_path)}/scheduler.pid"
|
129
140
|
if test "[ -e #{pid} ]"
|
130
141
|
execute :kill, "-s #{fetch(:resque_kill_signal)} $(cat #{pid}); rm #{pid}"
|
131
142
|
end
|