topological_inventory-providers-common 1.0.11 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2593d36aee528450e29282d903ddcc2d74c6593e9579c69ec2a510c9fcc15ab
4
- data.tar.gz: 47b0675fcab7eaab9c2b3899837b597295a0e7c6c737f1ce39ca49c4a7968cc5
3
+ metadata.gz: b81c523169c3ca87e678e3e7d046b4daee863200cf4eadd695e9022d17a11e5a
4
+ data.tar.gz: 1fc2a47cedf6f8d3b41f0df728a5ac8ceceaea03b58d43ef67da90680861c0eb
5
5
  SHA512:
6
- metadata.gz: 03f98f6334065f62a4462e30633c6a6d852552f49414be2293b4864d3971372ce66ab52d47e23b4a7ad2f8c0277d9d2352f38519e2621a80f6c9b2b011a7cdd4
7
- data.tar.gz: b801478114b42cc897329a12eca067cc707306f488ed7e84eddf7eddd91c0098dbbdf5d6d3fcb116734b39cd08d25dcabdd6731b60057fc900ca2c39a5008bd8
6
+ metadata.gz: 9afb8ba326d632ba59245d93837f32bd8edbcb34b3d82e029c351f904bb75f196592eb4724116a48caf0b7df8fc7f4101f5b59bd0e23b65d6fca25ada3ac4cb6
7
+ data.tar.gz: '00924d04d1fc4623cd4e0f0a719c5471dbd39635820375b4957278db1c6e3ecbdf2b58c25758bca22e91e979511286708279922919f6303118401e58ac9cc5c4'
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [1.0.12] - 2020-10-01
8
+ Add Operations Async Worker class #55
9
+
7
10
  ## [1.0.11]
8
11
  Make Collector Poll Time a parameter so we can tweak the collection interval #51
9
12
 
@@ -56,7 +59,8 @@ manageiq-loggers to >= 0.4.2 #20
56
59
  ## [1.0.0] - 2020-03-19
57
60
  ### Initial release to rubygems.org
58
61
 
59
- [Unreleased]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.11...HEAD
62
+ [Unreleased]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.12...HEAD
63
+ [1.0.12]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.11...v1.0.12
60
64
  [1.0.11]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.10...v1.0.11
61
65
  [1.0.10]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.9...v1.0.10
62
66
  [1.0.9]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.8...v1.0.9
@@ -0,0 +1,56 @@
1
+ require "topological_inventory/providers/common/logging"
2
+ require "topological_inventory/providers/common/operations/health_check"
3
+
4
+ module TopologicalInventory
5
+ module Providers
6
+ module Common
7
+ module Operations
8
+ class AsyncWorker
9
+ include Logging
10
+
11
+ def initialize(processor, queue = nil)
12
+ @processor = processor
13
+ @queue = queue || Queue.new
14
+ end
15
+
16
+ def start
17
+ return if thread.present?
18
+
19
+ @thread = Thread.new { listen }
20
+ end
21
+
22
+ def stop
23
+ thread&.exit
24
+ end
25
+
26
+ def enqueue(msg)
27
+ queue << msg
28
+ end
29
+
30
+ def listen
31
+ loop do
32
+ # the queue thread waits for a message to come during `Queue#pop`
33
+ msg = queue.pop
34
+ process_message(msg)
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ attr_reader :thread, :queue, :processor
41
+
42
+ def process_message(msg)
43
+ processor.process!(msg)
44
+ rescue => err
45
+ model, method = msg.message.to_s.split(".")
46
+ logger.error("#{model}##{method}: async worker failure: #{err.cause}\n#{err}\n#{err.backtrace.join("\n")}")
47
+ ensure
48
+ msg.ack
49
+ TopologicalInventory::Providers::Common::Operations::HealthCheck.touch_file
50
+ logger.debug("Operations::AsyncWorker queue length: #{queue.length}") if queue.length >= 20 && queue.length % 5 == 0
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,7 +1,7 @@
1
1
  module TopologicalInventory
2
2
  module Providers
3
3
  module Common
4
- VERSION = "1.0.11"
4
+ VERSION = "1.0.12"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,36 @@
1
+ require "topological_inventory/providers/common/operations/async_worker"
2
+
3
+ describe TopologicalInventory::Providers::Common::Operations::AsyncWorker do
4
+ let(:queue) { double }
5
+ let(:impl) { double }
6
+ let(:msg) { double }
7
+ subject { described_class.new(impl, queue) }
8
+
9
+ before do
10
+ allow(queue).to receive(:length).and_return(0)
11
+ allow(msg).to receive(:message).and_return("Source.availability_check")
12
+ end
13
+
14
+ context "when the message is able to be processed" do
15
+ before do
16
+ allow(impl).to receive(:process!).with(msg)
17
+ allow(msg).to receive(:ack)
18
+ end
19
+
20
+ it "drains messages that are added to the queue" do
21
+ expect(impl).to receive(:process!).with(msg).once
22
+ subject.send(:process_message, msg)
23
+ end
24
+ end
25
+
26
+ context "when the message results in an error" do
27
+ before do
28
+ allow(impl).to receive(:process!).with(msg).and_raise(StandardError.new("boom!"))
29
+ end
30
+
31
+ it "ack's the message on failure" do
32
+ expect(msg).to receive(:ack).once
33
+ subject.send(:process_message, msg)
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: topological_inventory-providers-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Slemr
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-04 00:00:00.000000000 Z
11
+ date: 2020-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -252,6 +252,7 @@ files:
252
252
  - lib/topological_inventory/providers/common/collector/parser.rb
253
253
  - lib/topological_inventory/providers/common/collectors_pool.rb
254
254
  - lib/topological_inventory/providers/common/logging.rb
255
+ - lib/topological_inventory/providers/common/operations/async_worker.rb
255
256
  - lib/topological_inventory/providers/common/operations/endpoint_client.rb
256
257
  - lib/topological_inventory/providers/common/operations/health_check.rb
257
258
  - lib/topological_inventory/providers/common/operations/processor.rb
@@ -269,6 +270,7 @@ files:
269
270
  - spec/topological_inventory/providers/common/collectors/inventory_collection_wrapper_spec.rb
270
271
  - spec/topological_inventory/providers/common/collectors_pool_spec.rb
271
272
  - spec/topological_inventory/providers/common/logger_spec.rb
273
+ - spec/topological_inventory/providers/common/operations/async_worker_spec.rb
272
274
  - spec/topological_inventory/providers/common/operations/processor_spec.rb
273
275
  - spec/topological_inventory/providers/common/operations/source_spec.rb
274
276
  - spec/topological_inventory/providers/common/save_inventory/saver_spec.rb