inst-jobs 2.2.0 → 2.2.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: c062c222e731bd490efe572108a508bf78faabee4479f7fe6927a89688d9ef0b
4
- data.tar.gz: 3b1678fc017230e990bc7e8d4e652c23ab59413953ce72a312b13adfa7626193
3
+ metadata.gz: 9550c353f31dc1d34a15993bdfbf279d87979ebb625ae776fb6727d7dc9e897e
4
+ data.tar.gz: 379f8faac5d3369551b4012a00f522d7871a4001776120c4e02535b70bdef8a3
5
5
  SHA512:
6
- metadata.gz: 8c1a722c17c9abc8f5c8a44cb28f6584dc9fb16c1edcccc8df566ad21a5f81af7a54fb70282e2689aee11947dcd96f44ca01dfe542d71c8d3d6b7f145a572ce7
7
- data.tar.gz: 9a7a65c71820d4b04f1e1ac2bf498cf030490a597d075d87d4399a392a7da1bbf50cfb3d5eeb1dea9c357d11e00aabf5e469f062c1fe9cc4b02cc8ed08e1a192
6
+ metadata.gz: 4dbb7a9366256f16a0fd7fbf22938d94c7754cdd3d9189d3d7d94e0d8deda59859ec4822f1e3c1d05cc7a2a67c8501a79c83d7b0b69f91fd106d9b24b4f35b06
7
+ data.tar.gz: 637e09a985feeef6144e5b172a04c8ceee5980eed3b1b49f2597e33bbf26522c43244bc2778905ba400cf0de6485166258103e09aa7a765e261f8971b89b2c06
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Delayed
4
- VERSION = "2.2.0"
4
+ VERSION = "2.2.1"
5
5
  end
@@ -9,52 +9,49 @@ module Delayed
9
9
  class ConsulHealthCheck < HealthCheck
10
10
  self.type_name = :consul
11
11
 
12
- CONSUL_CONFIG_KEYS = %w{url host port ssl token connect_timeout receive_timeout send_timeout}.map(&:freeze).freeze
12
+ CONSUL_CONFIG_KEYS = %w{url acl_token}.map(&:freeze).freeze
13
13
  DEFAULT_SERVICE_NAME = 'inst-jobs_worker'.freeze
14
- attr_reader :agent_client, :catalog_client
14
+ attr_reader :service_client, :health_client
15
15
 
16
16
  def initialize(*, **)
17
17
  super
18
18
  # Because we don't want the consul client to be a hard dependency we're
19
19
  # only requiring it once it's absolutely needed
20
- require 'imperium'
20
+ require 'diplomat'
21
21
 
22
22
  if config.keys.any? { |k| CONSUL_CONFIG_KEYS.include?(k) }
23
- consul_config = Imperium::Configuration.new.tap do |conf|
23
+ consul_config = Diplomat::Configuration.new.tap do |conf|
24
24
  CONSUL_CONFIG_KEYS.each do |key|
25
25
  conf.send("#{key}=", config[key]) if config[key]
26
26
  end
27
27
  end
28
- @agent_client = Imperium::Agent.new(consul_config)
29
- @catalog_client = Imperium::Catalog.new(consul_config)
28
+ @service_client = Diplomat::Service.new(configuration: consul_config)
29
+ @health_client = Diplomat::Health.new(configuration: consul_config)
30
30
  else
31
- @agent_client = Imperium::Agent.default_client
32
- @catalog_client = Imperium::Catalog.default_client
31
+ @service_client = Diplomat::Service.new
32
+ @health_client = Diplomat::Health.new
33
33
  end
34
34
  end
35
35
 
36
36
  def start
37
- service = Imperium::Service.new({
37
+ @service_client.register({
38
38
  id: worker_name,
39
39
  name: service_name,
40
+ check: check_attributes
40
41
  })
41
- service.add_check(check_attributes)
42
- response = @agent_client.register_service(service)
43
- response.ok?
44
42
  end
45
43
 
46
44
  def stop
47
- response = @agent_client.deregister_service(worker_name)
48
- response.ok? || response.not_found?
45
+ @service_client.deregister(worker_name)
49
46
  end
50
47
 
51
48
  def live_workers
52
- live_nodes = @catalog_client.list_nodes_for_service(service_name)
53
- if live_nodes.ok?
54
- live_nodes.map(&:service_id)
55
- else
56
- raise "Unable to read from Consul catalog: #{live_nodes.content}"
57
- end
49
+ # Filter out critical workers (probably nodes failing their serf health check)
50
+ live_nodes = @health_client.service(service_name, {
51
+ filter: 'not Checks.Status == critical'
52
+ })
53
+
54
+ live_nodes.map { |n| n.Service['ID']}
58
55
  end
59
56
 
60
57
  private
@@ -1,76 +1,63 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
- require 'imperium'
5
4
 
6
5
  RSpec.describe Delayed::Worker::ConsulHealthCheck do
7
6
  let(:health_check) { Delayed::Worker::ConsulHealthCheck.new(worker_name: 'foobar') }
8
7
 
9
- # can't use a verifying double for the response because the methods we're
10
- # tryig to stub are actually on HTTP::Message
11
- let(:response) { double('Imperium::Response') }
12
- let(:agent_client) { instance_double(Imperium::Agent) }
13
-
14
- before do
15
- allow(Imperium::Agent).to receive(:default_client).and_return(agent_client)
16
- end
17
-
18
8
  describe '#initialize' do
19
- it 'must use the default agent client when the config is mostly empty' do
9
+ it 'must use a default service client when the config is mostly empty' do
20
10
  check = Delayed::Worker::ConsulHealthCheck.new(worker_name: 'foobar')
21
- expect(check.agent_client).to eq Imperium::Agent.default_client
11
+ expect(check.service_client.configuration.url.to_s).to eq 'http://localhost:8500'
22
12
  end
23
13
 
24
- it 'must create a new agent API client when the config has relevant keys set' do
14
+ it 'must create a new service API client when the config has relevant keys set' do
25
15
  check = Delayed::Worker::ConsulHealthCheck.new(worker_name: 'foobar', config: {url: 'http://consul.example.com:8500'})
26
- agent_client = check.agent_client
27
- expect(agent_client).to_not eq Imperium::Agent.default_client
28
- expect(agent_client.config.url.to_s).to eq 'http://consul.example.com:8500'
16
+ service_client = check.service_client
17
+ expect(service_client.configuration.url.to_s).to eq 'http://consul.example.com:8500'
29
18
  end
30
19
  end
31
20
 
32
21
  describe '#start' do
33
22
  it 'must register this process as a service with consul' do
34
- expect(response).to receive(:ok?).and_return(true)
35
- expect(agent_client).to receive(:register_service)
36
- .with(an_instance_of(Imperium::Service))
37
- .and_return(response)
23
+ stub = stub_request(:put, "localhost:8500/v1/agent/service/register")
24
+ .with(body: hash_including({id: 'foobar' }))
25
+
38
26
  health_check.start
27
+
28
+ expect(stub).to have_been_requested
39
29
  end
40
30
 
41
31
 
42
32
  it 'must supply a args style check' do
43
- allow(response).to receive(:ok?).and_return(true)
44
- allow(agent_client).to receive(:register_service) { |service|
45
- check = service.checks.first
46
- expect(check.args).to_not be_nil
47
- response
48
- }
33
+ stub = stub_request(:put, "localhost:8500/v1/agent/service/register")
34
+ .with(body: hash_including({check: WebMock::API.hash_including({args: anything})}))
35
+
49
36
  health_check.start
37
+
38
+ expect(stub).to have_been_requested
50
39
  end
51
40
 
52
41
  it 'must include the docker container id when the docker option is set to true' do
42
+ stub = stub_request(:put, "localhost:8500/v1/agent/service/register")
43
+ .with(body: hash_including({check: WebMock::API.hash_including({docker_container_id: anything})}))
44
+
53
45
  local_health_check = Delayed::Worker::ConsulHealthCheck.new(
54
46
  worker_name: 'foobar',
55
47
  config: {docker: true}
56
48
  )
57
- allow(response).to receive(:ok?).and_return(true)
58
- allow(agent_client).to receive(:register_service) { |service|
59
- check = service.checks.first
60
- expect(check.docker_container_id).to_not be_nil
61
- response
62
- }
63
49
  local_health_check.start
50
+
51
+ expect(stub).to have_been_requested
64
52
  end
65
53
  end
66
54
 
67
55
  describe '#stop' do
68
56
  it 'must deregister the service from consul' do
69
- allow(response).to receive(:ok?).and_return(true)
70
- expect(agent_client).to receive(:deregister_service)
71
- .with(health_check.worker_name)
72
- .and_return(response)
57
+ stub = stub_request(:put, "localhost:8500/v1/agent/service/deregister/foobar")
58
+
73
59
  health_check.stop
60
+ expect(stub).to have_been_requested
74
61
  end
75
62
  end
76
63
  end
data/spec/spec_helper.rb CHANGED
@@ -7,6 +7,8 @@ require 'database_cleaner'
7
7
  require 'rack/test'
8
8
  require 'test_after_commit' if ::Rails.version < '5'
9
9
  require 'timecop'
10
+ require 'webmock/rspec'
11
+
10
12
  require 'pry'
11
13
  require 'byebug'
12
14
 
@@ -19,6 +21,7 @@ RSpec.configure do |config|
19
21
  config.before(:suite) do
20
22
  DatabaseCleaner.strategy = :transaction
21
23
  DatabaseCleaner.clean_with(:truncation)
24
+ WebMock.disable_net_connect!
22
25
  end
23
26
 
24
27
  config.before(:each) do |example|
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inst-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Luetke
8
8
  - Brian Palmer
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-01-06 00:00:00.000000000 Z
12
+ date: 2021-02-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -172,33 +172,33 @@ dependencies:
172
172
  - !ruby/object:Gem::Version
173
173
  version: 1.6.1
174
174
  - !ruby/object:Gem::Dependency
175
- name: imperium
175
+ name: diplomat
176
176
  requirement: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ">="
178
+ - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: 0.5.2
180
+ version: 2.5.1
181
181
  type: :development
182
182
  prerelease: false
183
183
  version_requirements: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - ">="
185
+ - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: 0.5.2
187
+ version: 2.5.1
188
188
  - !ruby/object:Gem::Dependency
189
189
  name: pg
190
190
  requirement: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - "<"
192
+ - - ">="
193
193
  - !ruby/object:Gem::Version
194
- version: '1.0'
194
+ version: '0'
195
195
  type: :development
196
196
  prerelease: false
197
197
  version_requirements: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - "<"
199
+ - - ">="
200
200
  - !ruby/object:Gem::Version
201
- version: '1.0'
201
+ version: '0'
202
202
  - !ruby/object:Gem::Dependency
203
203
  name: pry
204
204
  requirement: !ruby/object:Gem::Requirement
@@ -311,6 +311,20 @@ dependencies:
311
311
  - - '='
312
312
  - !ruby/object:Gem::Version
313
313
  version: 0.7.1
314
+ - !ruby/object:Gem::Dependency
315
+ name: webmock
316
+ requirement: !ruby/object:Gem::Requirement
317
+ requirements:
318
+ - - ">="
319
+ - !ruby/object:Gem::Version
320
+ version: '0'
321
+ type: :development
322
+ prerelease: false
323
+ version_requirements: !ruby/object:Gem::Requirement
324
+ requirements:
325
+ - - ">="
326
+ - !ruby/object:Gem::Version
327
+ version: '0'
314
328
  - !ruby/object:Gem::Dependency
315
329
  name: wwtd
316
330
  requirement: !ruby/object:Gem::Requirement
@@ -325,7 +339,7 @@ dependencies:
325
339
  - - "~>"
326
340
  - !ruby/object:Gem::Version
327
341
  version: 1.4.0
328
- description:
342
+ description:
329
343
  email:
330
344
  - brianp@instructure.com
331
345
  executables:
@@ -441,7 +455,7 @@ files:
441
455
  homepage: https://github.com/instructure/inst-jobs
442
456
  licenses: []
443
457
  metadata: {}
444
- post_install_message:
458
+ post_install_message:
445
459
  rdoc_options: []
446
460
  require_paths:
447
461
  - lib
@@ -456,8 +470,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
456
470
  - !ruby/object:Gem::Version
457
471
  version: '0'
458
472
  requirements: []
459
- rubygems_version: 3.0.3
460
- signing_key:
473
+ rubygems_version: 3.1.4
474
+ signing_key:
461
475
  specification_version: 4
462
476
  summary: Instructure-maintained fork of delayed_job
463
477
  test_files: