sidekiq-redeploy 0.1.8 → 0.1.9

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
  SHA256:
3
- metadata.gz: 622ce6da0eb4f0f2507ff8b5ba81cb24909118469e552d856139e25b0b5bb328
4
- data.tar.gz: c968b066fa65f1c4ab70345af149774cd8a2483abc0970103a3c50eb99893b47
3
+ metadata.gz: 8b4a9ea82326d3303e7b62977a3a124415b5b763ad3ab12e952fff7464794910
4
+ data.tar.gz: 9b876740e30131c3c6c4c3da743d04cb5922e616af690b1ad6561bb716e2e973
5
5
  SHA512:
6
- metadata.gz: dd933b670a81709895c6e2fe057421f8aa354297b54b303d7364aaaf618f1f7673074769d561794b6f9e24bde1a765e081940e14c9cc8f88488c57b5ce04169d
7
- data.tar.gz: 80aa2eac63fe6baca128a5eb0eab93c3833e2df0f529ec6b9078eedd8e23277484d4bd51dcb5fa25e79e73077cd5066e714b3249908a8da2fdef1cfea3e45f79
6
+ metadata.gz: 28ac5b4d9853c1538e1db4a98144280d2814d3a3799a3e3e0297db54b470e2cc13b9c721e7d0cf0c8a37cc23b764581fa6206e524eb973b5b3633934b7aff4c1
7
+ data.tar.gz: a7699606e5abba66b5d2ef82b11317de3ece6042234ab45d1491b61ab8e2ceec1fcfa7c9d71a79c6242405fe773b21e0b16b73e46c221a465b65ace4c296589d
data/.rubocop.yml CHANGED
@@ -19,7 +19,10 @@ Metrics/MethodLength:
19
19
  Max: 30
20
20
 
21
21
  Metrics/ClassLength:
22
- Max: 120
22
+ Max: 140
23
+
24
+ Metrics/AbcSize:
25
+ Max: 20
23
26
 
24
27
  RSpec/NestedGroups:
25
28
  Max: 4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## v0.1.9
2
+
3
+ **Fixes and enhancements:**
4
+
5
+ - Allow users to specify number of sidekiq worker processes with -n flag
6
+
1
7
  ## v0.1.8
2
8
 
3
9
  **Fixes and enhancements:**
data/README.md CHANGED
@@ -40,6 +40,7 @@ Usage: sidekiq-loader [options]
40
40
  -y, --watch-delay INTEGER [Optional] Specify the number of seconds between checking watch file. Defaults to 30.
41
41
  -d, --[no-]deploy [FLAG] [Optional] Deploy archive on app startup. Defaults to true.
42
42
  -s, --sidekiq-app [PATH|DIR] [Optional] Location of application to pass to sidekiq.
43
+ -n, --num-procs INTEGER [Optional] Specify the number of sidekiq processes to create. Defaults to 1.
43
44
  ```
44
45
 
45
46
  For example this will start the launcher using a S3 watch file.
data/bin/sidekiq-loader CHANGED
@@ -13,7 +13,8 @@ def run_sidekiq(ops, logger)
13
13
  deployer.deploy(source: deployer.archive_file) if ops[:deploy]
14
14
  config = { watch_delay: ops[:watch_delay] }
15
15
 
16
- Sidekiq::Redeploy::Loader.new(deployer:, logger:, sidekiq_app: ops[:sidekiq_app], config:).run
16
+ Sidekiq::Redeploy::Loader.new(deployer:, logger:, sidekiq_app: ops[:sidekiq_app], config:,
17
+ num_processes: ops[:num_processes]).run
17
18
  end
18
19
 
19
20
  def option_parser(opts)
@@ -39,6 +40,11 @@ def option_parser(opts)
39
40
  o.on '-s', '--sidekiq-app [PATH|DIR]', '[Optional] Location of application to pass to sidekiq.' do |arg|
40
41
  opts[:sidekiq_app] = arg
41
42
  end
43
+
44
+ o.on '-n', '--num-procs INTEGER', Integer,
45
+ '[Optional] Specify the number of sidekiq processes to create. Defaults to 1.' do |arg|
46
+ opts[:num_processes] = arg
47
+ end
42
48
  end
43
49
  end
44
50
 
@@ -15,9 +15,8 @@ module Sidekiq
15
15
 
16
16
  SIGNALS = [INT, TERM, USR2, TTIN].freeze
17
17
 
18
- def initialize(deployer:, sidekiq_app: nil, logger: Logger.new($stdout), config: {})
18
+ def initialize(deployer:, sidekiq_app: nil, logger: Logger.new($stdout), config: {}, num_processes: 1)
19
19
  require 'sidekiq/cli'
20
-
21
20
  @reload_sidekiq = false
22
21
  @exit_loader = false
23
22
  @loader_pid = ::Process.pid
@@ -28,6 +27,8 @@ module Sidekiq
28
27
  @loop_delay = config[:loop_delay] || 0.5
29
28
  @deployer = deployer
30
29
  @sidekiq_app = sidekiq_app
30
+ @num_processes = num_processes || 1
31
+ @sidekiq_pids = []
31
32
  end
32
33
 
33
34
  def run
@@ -46,7 +47,7 @@ module Sidekiq
46
47
  rescue StandardError => e
47
48
  log "Error in sidekiq loader: #{e.message}"
48
49
  log e.backtrace.join("\n")
49
- stop_sidekiq(@sidekiq_pid)
50
+ stop_sidekiq(@sidekiq_pids)
50
51
  ::Process.waitall
51
52
  exit 1
52
53
  end
@@ -62,12 +63,12 @@ module Sidekiq
62
63
  reload_app { deployer.deploy(source: deployer.archive_file) }
63
64
  elsif reload_sidekiq
64
65
  reload_app
65
- elsif process_died?(@sidekiq_pid)
66
- fork_sidekiq
67
66
  end
67
+ @sidekiq_pids = running_pids(@sidekiq_pids)
68
+ fork_sidekiq(@num_processes - @sidekiq_pids.length) if @sidekiq_pids.length < @num_processes
68
69
  next unless exit_loader
69
70
 
70
- stop_sidekiq(@sidekiq_pid)
71
+ stop_sidekiq(@sidekiq_pids)
71
72
  break
72
73
  end
73
74
  end
@@ -80,30 +81,32 @@ module Sidekiq
80
81
  end
81
82
 
82
83
  def reload_app
83
- quiet_sidekiq(@sidekiq_pid)
84
+ quiet_sidekiq(@sidekiq_pids)
84
85
 
85
86
  yield if block_given?
86
87
 
87
- stop_sidekiq(@sidekiq_pid)
88
+ stop_sidekiq(@sidekiq_pids)
88
89
 
89
90
  # wait for sidekiq to stop
90
91
  ::Process.waitall
91
-
92
92
  fork_sidekiq
93
93
  @reload_sidekiq = false
94
94
  end
95
95
 
96
- def fork_sidekiq
97
- @sidekiq_pid = ::Process.fork do
98
- cli = Sidekiq::CLI.instance
99
- args = @sidekiq_app ? ['-r', @sidekiq_app] : []
100
- cli.parse(args)
101
- cli.run
102
- rescue StandardError => e
103
- message = "Error loading sidekiq process: #{e.message}"
104
- log message
105
- log e.backtrace.join("\n")
106
- raise message
96
+ def fork_sidekiq(num_children = @num_processes)
97
+ num_children.times do
98
+ pid = ::Process.fork do
99
+ cli = Sidekiq::CLI.instance
100
+ args = @sidekiq_app ? ['-r', @sidekiq_app] : []
101
+ cli.parse(args)
102
+ cli.run
103
+ rescue StandardError => e
104
+ message = "Error loading sidekiq process: #{e.message}"
105
+ log message
106
+ log e.backtrace.join("\n")
107
+ raise message
108
+ end
109
+ @sidekiq_pids << pid
107
110
  end
108
111
  end
109
112
 
@@ -126,32 +129,41 @@ module Sidekiq
126
129
  when USR2
127
130
  @reload_sidekiq = true
128
131
  when TTIN
129
- ::Process.kill(signal, @sidekiq_pid)
132
+ @sidekiq_pids.each do |pid|
133
+ ::Process.kill(signal, pid)
134
+ end
130
135
  when TERM, INT
131
136
  @exit_loader = true
132
137
  end
133
138
  end
134
139
 
135
140
  def debug_handler(signal)
136
- log_data = { signal:, current_pid: ::Process.pid, loader_pid: @loader_pid, sidekiq_pid: @sidekiq_pid,
141
+ log_data = { signal:, current_pid: ::Process.pid, loader_pid: @loader_pid, sidekiq_pids: @sidekiq_pids,
137
142
  reload_sidekiq: @reload_sidekiq, exit_loader: @exit_loader }
138
143
  puts "handle_signal called with #{log_data}"
139
144
  end
140
145
 
141
- def stop_sidekiq(pid)
142
- ::Process.kill(TERM, pid) if pid
146
+ def stop_sidekiq(pids)
147
+ pids.each do |pid|
148
+ ::Process.kill(TERM, pid)
149
+ end
150
+ @sidekiq_pids = []
143
151
  end
144
152
 
145
- def quiet_sidekiq(pid)
146
- ::Process.kill(TSTP, pid) if pid
153
+ def quiet_sidekiq(pids)
154
+ pids.each do |pid|
155
+ ::Process.kill(TSTP, pid)
156
+ end
147
157
  end
148
158
 
149
- def process_died?(pid)
150
- return false if @exit_loader
151
-
152
- !::Process.getpgid(pid)
153
- rescue StandardError
154
- true
159
+ def running_pids(pids)
160
+ new_pids = []
161
+ pids.each do |pid|
162
+ new_pids << pid unless ::Process.waitpid(pid, ::Process::WNOHANG)
163
+ rescue Errno::ECHILD
164
+ log "PID #{pid} does not exist."
165
+ end
166
+ new_pids
155
167
  end
156
168
 
157
169
  def log(message)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Redeploy
5
- VERSION = '0.1.8'
5
+ VERSION = '0.1.9'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-redeploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - tbeauvais
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-22 00:00:00.000000000 Z
11
+ date: 2024-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puma-redeploy