process_balancer 1.0.0 → 1.1.1

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: 9e2b7936e66ec20f0b2cf36e107dd9a2aae52bdd19e03617f44d6e36abd5c008
4
- data.tar.gz: 5c7b264651a91513a59545e2fdcbbfca0bd13d079c4787e8fce3c90370e3d59c
3
+ metadata.gz: 869b9d54b977304ac3c13b5057a118ae19b776dc37b7d72e74435efc320a8553
4
+ data.tar.gz: 0e4a88eb0abdf6082043230b66c67483302d243299113c2605f0e33348d4f985
5
5
  SHA512:
6
- metadata.gz: 1c846bde2ec1126116b529471e338e3caec0bd87695f38e6fd61bbfca5e9bdf29c888dbb55b99a7b849dc3584c1807d95ddd198f05eec6fb0ba837d24c5a313d
7
- data.tar.gz: 3aab7f4a78e10282065c1dfba9c7d39ea74e489d52de600c85f42e6608aab07864380aa36df49a8f13c2b3e4929230d010ed782561614648f98f81696ebd72d1
6
+ metadata.gz: b7d63f8c3666194555442c36c1c0c1dbdee211e59b664791450c46fd7981cab515cd2db949c20c4280af5f38e728c44153339f493d4535ea93e56528d57fefe3
7
+ data.tar.gz: a269ac7431b7a038bfb20f029e0fdd79a1817d66b2130aca405455a0a271a08ee1275f28c3f0ff456942cc61b5deaa2aa67d63bcee874e6311faa42b30edac6a
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Next]
8
+ ### Added
9
+ ### Changed
10
+ ### Fixed
11
+
12
+ ## [1.1.1]
13
+ ### Fixed
14
+ - handle better redis gem before 4.2 and post 4.2
15
+
16
+ ## [1.1.0]
17
+ ### Changed
18
+ - handle pruning stale workers from the process list
19
+ - updated rubocop
20
+ ### Fixed
21
+ - fixed duplicating defaults
22
+
23
+ ## [1.0.0]
24
+ ### Added
25
+ - initial process balancer release
@@ -15,8 +15,8 @@ module ProcessBalancer # :nodoc:
15
15
  WORKER_COUNT_KEY = 'worker_counts'
16
16
 
17
17
  DEFAULTS = {
18
- redis: {},
19
- job_sets: [],
18
+ redis: {}.freeze,
19
+ job_sets: [].freeze,
20
20
  require: '.',
21
21
  max_threads: 10,
22
22
  shutdown_timeout: 30,
@@ -24,7 +24,12 @@ module ProcessBalancer # :nodoc:
24
24
  }.freeze
25
25
 
26
26
  def self.options
27
- @options ||= DEFAULTS.dup
27
+ @options ||= begin
28
+ o = DEFAULTS.dup
29
+ o[:redis] = o[:redis].dup
30
+ o[:job_sets] = o[:job_sets].dup
31
+ o
32
+ end
28
33
  end
29
34
 
30
35
  def self.options=(opts)
@@ -49,7 +54,7 @@ module ProcessBalancer # :nodoc:
49
54
  end
50
55
 
51
56
  def self.logger
52
- @logger ||= Logger.new(STDOUT, level: Logger::INFO)
57
+ @logger ||= Logger.new($stdout, level: Logger::INFO)
53
58
  end
54
59
 
55
60
  def self.redis
@@ -124,7 +129,7 @@ module ProcessBalancer # :nodoc:
124
129
  data = c.hget("#{worker}:workers", job_id)
125
130
  if data
126
131
  data = JSON.parse(data, symbolize_names: true)
127
- count += (data.dig(:running)&.size || 0)
132
+ count += (data[:running]&.size || 0)
128
133
  end
129
134
  rescue JSON::ParserError
130
135
  nil
@@ -151,7 +151,7 @@ module ProcessBalancer
151
151
 
152
152
  opts = {}
153
153
  # pull in global config
154
- opts.merge!(config.dig(:global) || {})
154
+ opts.merge!(config[:global] || {})
155
155
  # pull in ENV override config
156
156
  opts.merge!(config.dig(:environments, environment.to_sym) || {})
157
157
 
@@ -212,7 +212,7 @@ module ProcessBalancer
212
212
  # Heroku sends TERM and then waits 30 seconds for process to exit.
213
213
  raise Interrupt
214
214
  },
215
- USR1: lambda { |cli|
215
+ USR1: lambda { |cli| # rubocop: disable Naming/VariableNumber
216
216
  ProcessBalancer.logger.info 'Received USR1, no longer accepting new work'
217
217
  cli.manager.quiet
218
218
  },
@@ -121,7 +121,18 @@ module ProcessBalancer
121
121
  redis do |c|
122
122
  c.watch(PROCESSES_KEY)
123
123
 
124
- workers = c.lrange(PROCESSES_KEY, 0, -1)
124
+ workers = c.lrange(PROCESSES_KEY, 0, -1)
125
+ stale_ids = workers.reject { |i| [true, 1].include?(c.exists(i)) }
126
+ unless stale_ids.empty?
127
+ c.multi do
128
+ stale_ids.each do |id|
129
+ c.lrem(PROCESSES_KEY, 0, id)
130
+ end
131
+ end
132
+ # re-fetch
133
+ c.watch(PROCESSES_KEY)
134
+ workers = c.lrange(PROCESSES_KEY, 0, -1)
135
+ end
125
136
  num_workers = workers.size
126
137
  index = workers.find_index(identity)
127
138
 
@@ -17,10 +17,8 @@ module ProcessBalancer
17
17
  @app = app
18
18
  end
19
19
 
20
- def call
21
- @app.reloader.wrap do
22
- yield
23
- end
20
+ def call(&block)
21
+ @app.reloader.wrap(&block)
24
22
  # ensure
25
23
  # ActiveRecord::Base.clear_active_connections!
26
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProcessBalancer
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.1'
5
5
  end
@@ -30,13 +30,13 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'bundler', '~> 1.17'
31
31
  spec.add_development_dependency 'climate_control', '~> 0.2'
32
32
  spec.add_development_dependency 'fakefs', '~> 1.2.2'
33
- spec.add_development_dependency 'mock_redis', '~> 0.23'
34
- spec.add_development_dependency 'rake', '~> 11.0'
33
+ spec.add_development_dependency 'mock_redis', '~> 0.24'
34
+ spec.add_development_dependency 'rake', '>= 12.3.3'
35
35
  spec.add_development_dependency 'redis-namespace', '~> 1.7'
36
36
  spec.add_development_dependency 'rspec', '~> 3.0'
37
37
  spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4'
38
- spec.add_development_dependency 'rubocop', '~> 0.83.0'
39
- spec.add_development_dependency 'rubocop-rspec', '~> 1.39.0'
38
+ spec.add_development_dependency 'rubocop', '~> 1.3.0'
39
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.0.0'
40
40
  spec.add_development_dependency 'simplecov', '~> 0.12'
41
41
 
42
42
  spec.add_dependency 'concurrent-ruby', '~> 1.1'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: process_balancer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edward Rudd
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-03 00:00:00.000000000 Z
11
+ date: 2020-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,28 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.23'
61
+ version: '0.24'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.23'
68
+ version: '0.24'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '11.0'
75
+ version: 12.3.3
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '11.0'
82
+ version: 12.3.3
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: redis-namespace
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -128,28 +128,28 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 0.83.0
131
+ version: 1.3.0
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 0.83.0
138
+ version: 1.3.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rubocop-rspec
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 1.39.0
145
+ version: 2.0.0
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 1.39.0
152
+ version: 2.0.0
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: simplecov
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -251,7 +251,7 @@ homepage: http://github.com/
251
251
  licenses:
252
252
  - LGPLv3
253
253
  metadata: {}
254
- post_install_message:
254
+ post_install_message:
255
255
  rdoc_options: []
256
256
  require_paths:
257
257
  - lib
@@ -266,8 +266,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
266
  - !ruby/object:Gem::Version
267
267
  version: '0'
268
268
  requirements: []
269
- rubygems_version: 3.0.6
270
- signing_key:
269
+ rubygems_version: 3.0.8
270
+ signing_key:
271
271
  specification_version: 4
272
272
  summary: A self-balancing long-running job runner
273
273
  test_files: []