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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3bfe5006adbe8559a89f1241947631148ede51d
4
- data.tar.gz: d013fb95fece584426fa16afd0d9fffc93026594
3
+ metadata.gz: cdf2b37120431a87cfb6a7033e7cd8b011ceec8f
4
+ data.tar.gz: a5b3dd8b2a3c7255304bfd0354334026d6d97ac6
5
5
  SHA512:
6
- metadata.gz: 6da3b0b2929b8791280f114762e011287831904c28751ec57f67c743555de0fb0311b903e2ceb1ae680912656064d34600d54d01920a07d8386c20687cf94421
7
- data.tar.gz: 3fabbb010fe20fdefc3a2622c7aa32b002a45cae0aaa25fd4f3fd0cbc93999e75f719ef1fbf31cf9ea8d790b3722b7071502820b472e93c71bc5500404531c7a
6
+ metadata.gz: b814fd76bcb8ad021a9c401dbeeb60fc3cef1260a70bcf7460f64dcd6596745128f8a25e655381179fb0b5b2a805b271aa5e6ee4894a25256d1591dc9ac10640
7
+ data.tar.gz: e2ba1646f82d892a275c708f29224d749cce5382b909691154469d3c078535ec496f377d57cf1e1795550c84fa9829858cc27ca4e279350be8931bb898dfc954
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [0.1.2][] (2017-01-12)
6
+
7
+ `sidekiq:start` checks that sidekiq really comes up and will retry a few times.
8
+
5
9
  ## [0.1.1][] (2016-09-29)
6
10
 
7
11
  Do not fail on first deploy.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- makandra_sidekiq (0.1.1)
4
+ makandra_sidekiq (0.1.2)
5
5
  capistrano (>= 3)
6
6
 
7
7
  GEM
@@ -36,14 +36,15 @@ module MakandraSidekiq
36
36
  puts 'Sidekiq is already running.'
37
37
  else
38
38
  puts 'Starting Sidekiq...'
39
- run_sidekiq
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
- @rails_env ||= ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
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 pid
58
- @pid ||= if pid_file.file?
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 run_sidekiq
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 "Sidekiqctl failed with message: #{stderr_str}"
147
+ fail "#{command} failed with message: #{stderr_str}"
117
148
  end
118
149
  end
119
150
 
@@ -1,3 +1,3 @@
1
1
  module MakandraSidekiq
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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: 2016-09-29 00:00:00.000000000 Z
11
+ date: 2017-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano