receptor_controller-client 0.0.5 → 0.0.6
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 +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/receptor_controller/client/directive_blocking.rb +1 -1
- data/lib/receptor_controller/client/directive_non_blocking.rb +1 -1
- data/lib/receptor_controller/client/response_worker.rb +46 -3
- data/lib/receptor_controller/client/version.rb +1 -1
- data/spec/receptor_controller/directive_blocking_spec.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f41b7d6f4bd570860329519b76db11ce76e7fd1938d05195d32700a88b373b4d
|
4
|
+
data.tar.gz: 3720db1535834c0ad565aed6f1d9d6b99a78395b46cfd11be65ab29dc2ce5942
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e08b4c2d9590b7ec470a5703432d6504ed928fefc219adee040df5db9d9c5fa69d31e0f5f1ab6a8476ec981c694b111999ab27be484fe005228c3e9b7e25e401
|
7
|
+
data.tar.gz: 4ac74ec793767207779c7cb6d952712d4335c87ee249638cf714ce3a30775e3b18a96b114ead27585fe026da52077a78b6c5bb9997176d3f06f092d7f37912af
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,9 @@ 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
7
|
## [Unreleased]
|
8
|
+
## [0.0.6]
|
9
|
+
- Waiting for response-worker kafka init #20
|
10
|
+
- Fix href_slug in directives log #29
|
8
11
|
|
9
12
|
## [0.0.5] - 2020-08-11
|
10
13
|
### Added
|
@@ -24,7 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
24
27
|
### Added
|
25
28
|
- Added extra logging for messages
|
26
29
|
|
27
|
-
[Unreleased]: https://github.com/RedHatInsights/receptor_controller-client-ruby/compare/v0.0.
|
30
|
+
[Unreleased]: https://github.com/RedHatInsights/receptor_controller-client-ruby/compare/v0.0.6...HEAD
|
31
|
+
[0.0.6]: https://github.com/RedHatInsights/receptor_controller-client-ruby/releases/tag/v0.0.6
|
28
32
|
[0.0.5]: https://github.com/RedHatInsights/receptor_controller-client-ruby/releases/tag/v0.0.5
|
29
33
|
[0.0.4]: https://github.com/RedHatInsights/receptor_controller-client-ruby/releases/tag/v0.0.4
|
30
34
|
[0.0.3]: https://github.com/RedHatInsights/receptor_controller-client-ruby/releases/tag/v0.0.3
|
@@ -20,7 +20,7 @@ module ReceptorController
|
|
20
20
|
|
21
21
|
msg_id = JSON.parse(response.body)['id']
|
22
22
|
|
23
|
-
logger.debug("Receptor response [#{ReceptorController::Client::Configuration.default.queue_persist_ref}]: registering message #{msg_id}, href_slug: #{
|
23
|
+
logger.debug("Receptor response [#{ReceptorController::Client::Configuration.default.queue_persist_ref}]: registering message #{msg_id}, href_slug: #{log_message_common}")
|
24
24
|
# registers message id for kafka responses
|
25
25
|
response_worker.register_message(msg_id, self)
|
26
26
|
wait_for_response(msg_id)
|
@@ -48,7 +48,7 @@ module ReceptorController
|
|
48
48
|
|
49
49
|
# registers message id for kafka responses
|
50
50
|
response_worker.register_message(msg_id, self)
|
51
|
-
logger.debug("Receptor response [#{ReceptorController::Client::Configuration.default.queue_persist_ref}]: registering message #{msg_id}, href_slug: #{
|
51
|
+
logger.debug("Receptor response [#{ReceptorController::Client::Configuration.default.queue_persist_ref}]: registering message #{msg_id}, href_slug: #{log_message_common}")
|
52
52
|
|
53
53
|
msg_id
|
54
54
|
else
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'active_support/notifications'
|
1
2
|
require 'base64'
|
2
3
|
require "concurrent"
|
3
4
|
require 'stringio'
|
@@ -20,6 +21,7 @@ module ReceptorController
|
|
20
21
|
class Client::ResponseWorker
|
21
22
|
EOF = "eof".freeze
|
22
23
|
RESPONSE = "response".freeze
|
24
|
+
INITIALIZATION_TIMEOUT = 20
|
23
25
|
|
24
26
|
attr_reader :started
|
25
27
|
alias started? started
|
@@ -39,13 +41,23 @@ module ReceptorController
|
|
39
41
|
|
40
42
|
# Start listening on Kafka
|
41
43
|
def start
|
44
|
+
init_lock, init_wait = Mutex.new, ConditionVariable.new
|
45
|
+
|
42
46
|
lock.synchronize do
|
43
47
|
return if started.value
|
44
48
|
|
49
|
+
default_messaging_opts # Thread-safe init
|
50
|
+
init_notifications(init_lock, init_wait)
|
51
|
+
|
45
52
|
started.value = true
|
46
53
|
workers[:maintenance] = Thread.new { check_timeouts while started.value }
|
47
54
|
workers[:listener] = Thread.new { listen while started.value }
|
48
55
|
end
|
56
|
+
|
57
|
+
# Wait for kafka initialization
|
58
|
+
wait_for_notifications(init_lock, init_wait)
|
59
|
+
|
60
|
+
logger.info("Receptor Response worker started...")
|
49
61
|
end
|
50
62
|
|
51
63
|
# Stop listener
|
@@ -59,6 +71,36 @@ module ReceptorController
|
|
59
71
|
end
|
60
72
|
end
|
61
73
|
|
74
|
+
# Listening for the consumer call to the Fetch API
|
75
|
+
# Then releasing original starting thread
|
76
|
+
def init_notifications(init_lock, init_wait)
|
77
|
+
logger.info("Initializing Receptor kafka client...")
|
78
|
+
start_time = Time.now.utc
|
79
|
+
ActiveSupport::Notifications.subscribe('request.connection.kafka') do |*args|
|
80
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
81
|
+
if default_messaging_opts[:client_ref] == event.payload[:client_id]
|
82
|
+
if event.payload[:api] == :fetch
|
83
|
+
logger.info "Receptor Kafka client successfully initialized "
|
84
|
+
# initialized, unsubscribe notifications
|
85
|
+
ActiveSupport::Notifications.unsubscribe('request.connection.kafka')
|
86
|
+
init_lock.synchronize { init_wait.signal }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
if start_time <= INITIALIZATION_TIMEOUT.seconds.ago.utc
|
91
|
+
ActiveSupport::Notifications.unsubscribe('request.connection.kafka')
|
92
|
+
logger.error("Receptor Kafka client initialization timeout...")
|
93
|
+
init_lock.synchronize { init_wait.signal }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def wait_for_notifications(init_lock, init_wait)
|
99
|
+
init_lock.synchronize do
|
100
|
+
init_wait.wait(init_lock)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
62
104
|
# Registers message_id received by request,
|
63
105
|
# Defines response and timeout callback methods
|
64
106
|
#
|
@@ -84,7 +126,6 @@ module ReceptorController
|
|
84
126
|
# Open a connection to the messaging service
|
85
127
|
client = ManageIQ::Messaging::Client.open(default_messaging_opts)
|
86
128
|
|
87
|
-
logger.info("Receptor Response worker started...")
|
88
129
|
client.subscribe_topic(queue_opts) do |message|
|
89
130
|
process_message(message)
|
90
131
|
end
|
@@ -221,12 +262,14 @@ module ReceptorController
|
|
221
262
|
@queue_opts = {:service => config.queue_topic,
|
222
263
|
:auto_ack => config.queue_auto_ack}
|
223
264
|
@queue_opts[:max_bytes] = config.queue_max_bytes if config.queue_max_bytes
|
224
|
-
@queue_opts[:persist_ref] =
|
265
|
+
@queue_opts[:persist_ref] = ENV['HOSTNAME']
|
225
266
|
@queue_opts
|
226
267
|
end
|
227
268
|
|
228
269
|
def default_messaging_opts
|
229
|
-
|
270
|
+
return @default_messaging_opts if @default_messaging_opts
|
271
|
+
|
272
|
+
@default_messaging_opts = {
|
230
273
|
:host => config.queue_host,
|
231
274
|
:port => config.queue_port,
|
232
275
|
:protocol => :Kafka,
|
@@ -32,6 +32,10 @@ RSpec.describe ReceptorController::Client::DirectiveBlocking do
|
|
32
32
|
|
33
33
|
subject { described_class.new(:name => directive, :account => external_tenant, :node_id => receptor_node, :payload => payload, :client => receptor_client) }
|
34
34
|
|
35
|
+
before do
|
36
|
+
allow(subject.response_worker).to receive_messages(:init_notifications => nil, :wait_for_notifications => nil)
|
37
|
+
end
|
38
|
+
|
35
39
|
describe "#call" do
|
36
40
|
it "makes POST /job request to receptor and registers received message ID" do
|
37
41
|
allow(subject).to receive(:wait_for_response)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: receptor_controller-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Slemr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|