makandra_sidekiq 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/makandra_sidekiq/sidekiq_control.rb +37 -6
- data/lib/makandra_sidekiq/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdf2b37120431a87cfb6a7033e7cd8b011ceec8f
|
4
|
+
data.tar.gz: a5b3dd8b2a3c7255304bfd0354334026d6d97ac6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b814fd76bcb8ad021a9c401dbeeb60fc3cef1260a70bcf7460f64dcd6596745128f8a25e655381179fb0b5b2a805b271aa5e6ee4894a25256d1591dc9ac10640
|
7
|
+
data.tar.gz: e2ba1646f82d892a275c708f29224d749cce5382b909691154469d3c078535ec496f377d57cf1e1795550c84fa9829858cc27ca4e279350be8931bb898dfc954
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -36,14 +36,15 @@ module MakandraSidekiq
|
|
36
36
|
puts 'Sidekiq is already running.'
|
37
37
|
else
|
38
38
|
puts 'Starting Sidekiq...'
|
39
|
-
|
39
|
+
patiently_start_sidekiq
|
40
|
+
puts 'Done.'
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
44
|
private
|
44
45
|
|
45
46
|
def rails_env
|
46
|
-
|
47
|
+
ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
47
48
|
end
|
48
49
|
|
49
50
|
def config_path
|
@@ -54,13 +55,14 @@ module MakandraSidekiq
|
|
54
55
|
@pid_file ||= @root.join(@config[:pidfile])
|
55
56
|
end
|
56
57
|
|
57
|
-
def
|
58
|
-
|
58
|
+
def read_pid
|
59
|
+
if pid_file.file?
|
59
60
|
pid_file.read.to_i
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
63
64
|
def running?
|
65
|
+
pid = read_pid
|
64
66
|
Process.kill(0, pid) if pid
|
65
67
|
rescue Errno::ESRCH
|
66
68
|
# not running
|
@@ -95,7 +97,36 @@ module MakandraSidekiq
|
|
95
97
|
bundle_exec('sidekiqctl', command, pid_file.to_s)
|
96
98
|
end
|
97
99
|
|
98
|
-
def
|
100
|
+
def patiently_start_sidekiq
|
101
|
+
remove_pid_file
|
102
|
+
try_times(5, error: "Sidekiq failed to start. Check #{@config[:logfile]}.") do |i|
|
103
|
+
puts "Trying to spawn (attempt #{i})..."
|
104
|
+
spawn_sidekiq
|
105
|
+
try_times(20, error: "Sidekiq did not create a PID file and probably failed to start. Check #{@config[:logfile]}.") do
|
106
|
+
pid_file_present?
|
107
|
+
end
|
108
|
+
sleep 10 # wait for any crashes during startup
|
109
|
+
running?
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def remove_pid_file
|
114
|
+
pid_file.delete if pid_file_present?
|
115
|
+
end
|
116
|
+
|
117
|
+
def pid_file_present?
|
118
|
+
pid_file.file?
|
119
|
+
end
|
120
|
+
|
121
|
+
def try_times(count, error:)
|
122
|
+
count.times do |i|
|
123
|
+
return if yield(i + 1)
|
124
|
+
sleep(1)
|
125
|
+
end
|
126
|
+
fail error
|
127
|
+
end
|
128
|
+
|
129
|
+
def spawn_sidekiq
|
99
130
|
arguments = [
|
100
131
|
'--index', sidekiq_index.to_s,
|
101
132
|
'--environment', rails_env,
|
@@ -113,7 +144,7 @@ module MakandraSidekiq
|
|
113
144
|
stdout_str, stderr_str, status = Open3.capture3('bundle', 'exec', *command, chdir: @root.to_s)
|
114
145
|
puts stdout_str
|
115
146
|
unless status.success?
|
116
|
-
fail "
|
147
|
+
fail "#{command} failed with message: #{stderr_str}"
|
117
148
|
end
|
118
149
|
end
|
119
150
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: makandra_sidekiq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Kraze
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|