switchman-inst-jobs 1.1.3 → 1.1.4

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: 5e9ee17c392694f339d9ce769cb0edca2a33f8fb71b573d44bb943a4d076ce96
4
- data.tar.gz: 748976de1add47043aca059e25fa667259c8f00a843ef023c65cec432b1c7fc3
3
+ metadata.gz: 35759761780a2dc32fb4e098517571bb5f4fba43435ed15771a497fd527ec133
4
+ data.tar.gz: 1ec1ffde947de99b9af7ef7f75830092ae4e9fabc651edf2cbf78b78a9cda5fa
5
5
  SHA512:
6
- metadata.gz: 339dc8140ddb2cf061c64d4eae47a926a198a593e08ffc84691bdf08f842c5bb12e4983a333f83141c88551c5b7d3b43ea5e2801e23a69aa02e9ea0f085ee17b
7
- data.tar.gz: 371062a3e07f2f7730687df17e8e268dfba4e61b45c4ce5db677b154b313cfba717af6051e2070231aa68422d9ff711e59da9c9427c2f9fce5d4ecbbc595d105
6
+ metadata.gz: e463c81e1a261e322ba4ce26974a8fc19e9ca68fbdf4c59c54cf9fc7b0a2e3fc6ca92e8092e02dbb94b2990c7152a7ca4f21254aa51e37fa951fc51630b16e33
7
+ data.tar.gz: 3919ccc98ea6bed1bdc8284eec26f7c3c3a282b49f43a81e4179a4535760b9d20533b6b477ef945e98f7f6f3e0bb273ca60eaca85969ab486bc68afc75789064
@@ -19,6 +19,7 @@ module SwitchmanInstJobs
19
19
  ::Delayed::Backend::Redis::Job.column :shard_id, :integer
20
20
  ::Delayed::Pool.prepend Delayed::Pool
21
21
  ::Delayed::Worker.prepend Delayed::Worker
22
+ ::Delayed::Worker::HealthCheck.prepend Delayed::Worker::HealthCheck
22
23
  ::Object.include Delayed::MessageSending
23
24
  end
24
25
 
@@ -39,6 +40,7 @@ require 'switchman_inst_jobs/delayed/backend/base'
39
40
  require 'switchman_inst_jobs/delayed/message_sending'
40
41
  require 'switchman_inst_jobs/delayed/pool'
41
42
  require 'switchman_inst_jobs/delayed/worker'
43
+ require 'switchman_inst_jobs/delayed/worker/health_check'
42
44
  require 'switchman_inst_jobs/railtie'
43
45
  require 'switchman_inst_jobs/shackles'
44
46
  require 'switchman_inst_jobs/switchman/database_server'
@@ -5,6 +5,16 @@ module SwitchmanInstJobs
5
5
  base.singleton_class.prepend(ClassMethods)
6
6
  end
7
7
 
8
+ def initialize(options = {})
9
+ # have to initialize this first, so #shard works
10
+ @config = options
11
+ ::Delayed::Worker::HealthCheck.munge_service_name(shard) do
12
+ super
13
+ # ensure to instantiate with the munged config
14
+ health_check
15
+ end
16
+ end
17
+
8
18
  def start
9
19
  shard.activate(:delayed_jobs) { super }
10
20
  end
@@ -0,0 +1,34 @@
1
+ module SwitchmanInstJobs
2
+ module Delayed
3
+ module Worker
4
+ module HealthCheck
5
+ def self.prepended(base)
6
+ base.singleton_class.prepend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def munge_service_name(shard)
11
+ # munge the name to add the current shard
12
+ original_service_name = ::Delayed::Settings.worker_health_check_config['service_name']
13
+ ::Delayed::Settings.worker_health_check_config['service_name'] = "#{original_service_name || ::Delayed::Worker::ConsulHealthCheck::DEFAULT_SERVICE_NAME}/#{shard.id}"
14
+ yield
15
+ ensure
16
+ ::Delayed::Settings.worker_health_check_config['service_name'] = original_service_name
17
+ end
18
+
19
+ def reschedule_abandoned_jobs(call_super: false)
20
+ shards = ::Switchman::Shard.delayed_jobs_shards
21
+ call_super = true if shards.length == 1
22
+ return munge_service_name(::Switchman::Shard.current(:delayed_jobs)) { super() } if call_super
23
+
24
+ ::Switchman::Shard.with_each_shard(shards, [:delayed_jobs]) do
25
+ self.send_later_enqueue_args(:reschedule_abandoned_jobs,
26
+ { singleton: "periodic: Delayed::Worker::HealthCheck.reschedule_abandoned_jobs:#{::Switchman::Shard.current(:delayed_jobs).id}" },
27
+ call_super: true)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -8,7 +8,7 @@ module SwitchmanInstJobs
8
8
  ::Switchman::Shard.lookup(config[:delayed_jobs_shard])
9
9
  # have to avoid recursion for the default shard asking for the default
10
10
  # shard's delayed_jobs_shard
11
- dj_shard ||= shard if shard.default?
11
+ dj_shard ||= shard if shard&.default?
12
12
  dj_shard || ::Switchman::Shard.default.delayed_jobs_shard
13
13
  end
14
14
  end
@@ -14,7 +14,7 @@ module SwitchmanInstJobs
14
14
  shard = ::Switchman::Shard.lookup(delayed_jobs_shard_id)
15
15
  return shard if shard
16
16
  end
17
- database_server.try(:delayed_jobs_shard, self)
17
+ database_server&.delayed_jobs_shard(self)
18
18
  end
19
19
 
20
20
  module ClassMethods
@@ -51,6 +51,22 @@ module SwitchmanInstJobs
51
51
  db = ::Switchman::DatabaseServer.server_for_new_shard
52
52
  db.create_new_shard
53
53
  end
54
+
55
+ def delayed_jobs_shards
56
+ @delayed_jobs_shards ||= begin
57
+ db_dj_shards = ::Switchman::DatabaseServer.all.map do |db|
58
+ next db.shards.to_a if db.config[:delayed_jobs_shard] == 'self'
59
+ db.delayed_jobs_shard
60
+ end.compact.flatten.uniq # yes, all three
61
+ shard_dj_shards = ::Switchman::Shard.
62
+ where.not(delayed_jobs_shard_id: nil).
63
+ distinct.
64
+ pluck(:delayed_jobs_shard_id).
65
+ map { |id| ::Switchman::Shard.lookup(id) }.
66
+ compact
67
+ (db_dj_shards + shard_dj_shards).uniq.sort
68
+ end
69
+ end
54
70
  end
55
71
  end
56
72
  end
@@ -1,3 +1,3 @@
1
1
  module SwitchmanInstJobs
2
- VERSION = '1.1.3'.freeze
2
+ VERSION = '1.1.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman-inst-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Petty
@@ -84,6 +84,34 @@ dependencies:
84
84
  - - "~>"
85
85
  - !ruby/object:Gem::Version
86
86
  version: '1.15'
87
+ - !ruby/object:Gem::Dependency
88
+ name: byebug
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ - !ruby/object:Gem::Dependency
102
+ name: imperium
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
87
115
  - !ruby/object:Gem::Dependency
88
116
  name: pg
89
117
  requirement: !ruby/object:Gem::Requirement
@@ -212,6 +240,7 @@ files:
212
240
  - lib/switchman_inst_jobs/delayed/message_sending.rb
213
241
  - lib/switchman_inst_jobs/delayed/pool.rb
214
242
  - lib/switchman_inst_jobs/delayed/worker.rb
243
+ - lib/switchman_inst_jobs/delayed/worker/health_check.rb
215
244
  - lib/switchman_inst_jobs/railtie.rb
216
245
  - lib/switchman_inst_jobs/shackles.rb
217
246
  - lib/switchman_inst_jobs/switchman/database_server.rb