fleck 2.0.0 → 2.1.0
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/examples/actions.rb +4 -3
- data/lib/fleck/core/consumer/actions.rb +3 -0
- data/lib/fleck/core/consumer/logger.rb +1 -1
- data/lib/fleck/core/consumer/request.rb +14 -3
- data/lib/fleck/version.rb +1 -1
- 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: dca817403e895fd00e7d95e54d278f19e13f0941960b276b501d637c9330f588
|
4
|
+
data.tar.gz: 93e27ca7cbd491413e0fc9199c7ba259d05c2d6bef11403ee7feaf403b00453a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6079c6cb3bc70d79e4cc576f7e358bb1043bf996700c073147155bb7c27178836a7f23a67bf1cae51c0a4665838f440c7b39bea64104c5978eb8a9f7eef7375
|
7
|
+
data.tar.gz: 6d12f8ffd73af744fd61d3620fc955a310a3b78b4bbf6f06b6070dae9c43f782b1cea0c12e158284e97af8a38ad0f5e34e7d1a16bbfff74edcb09ccc75334228
|
data/examples/actions.rb
CHANGED
@@ -28,8 +28,9 @@ class MyConsumer < Fleck::Consumer
|
|
28
28
|
end
|
29
29
|
|
30
30
|
action 'ciao', "An action which returns 'Ciao'"
|
31
|
+
param :world, type: 'boolean', required: true, default: false
|
31
32
|
def my_custom_method
|
32
|
-
ok! 'Ciao!'
|
33
|
+
ok! params[:world] ? 'Ciao, Mondo!' : 'Ciao!'
|
33
34
|
end
|
34
35
|
|
35
36
|
action :aloha
|
@@ -47,9 +48,9 @@ end
|
|
47
48
|
actions = %i[hello ciao aloha not_an_action]
|
48
49
|
|
49
50
|
SAMPLES.to_i.times do |num|
|
50
|
-
action = actions
|
51
|
+
action = actions.sample
|
51
52
|
name = ['John Doe', 'Willie Wonka', 'Billie Smith'].sample
|
52
|
-
client.request(action: action, params: { num: num, name: name, number: rand * 100 }, timeout: 5) do |_, response|
|
53
|
+
client.request(action: action, params: { num: num, name: name, number: rand * 100, world: %w[yes no].sample }, timeout: 5) do |_, response|
|
53
54
|
if response.status == 200
|
54
55
|
Fleck.logger.info "ACTION: (#{action.inspect}) #{response.body}"
|
55
56
|
else
|
@@ -49,6 +49,7 @@ module Fleck
|
|
49
49
|
action_name = request.action.to_s
|
50
50
|
action = actions[action_name]
|
51
51
|
unless action
|
52
|
+
request.log_headers_and_params!
|
52
53
|
message = "Action #{action_name.inspect} not found!"
|
53
54
|
not_found! error: message, body: [
|
54
55
|
{ type: 'action', name: action_name, value: action_name, error: 'not_found', message: message }
|
@@ -58,12 +59,14 @@ module Fleck
|
|
58
59
|
# iterate over action params and use param options to validate incoming request params.
|
59
60
|
action[:params].each { |_, param| validate_action_param!(param) }
|
60
61
|
|
62
|
+
request.log_headers_and_params!
|
61
63
|
send(action[:method_name])
|
62
64
|
end
|
63
65
|
|
64
66
|
def validate_action_param!(param)
|
65
67
|
validation = param.validate(request.params[param.name])
|
66
68
|
unless validation.valid?
|
69
|
+
request.log_headers_and_params!
|
67
70
|
bad_request! error: "Invalid param value: #{param.name} = #{validation.value.inspect}",
|
68
71
|
body: validation.errors
|
69
72
|
end
|
@@ -67,7 +67,7 @@ module Fleck
|
|
67
67
|
|
68
68
|
def exchange_and_queue_name
|
69
69
|
ex_name = rmq_exchange_name.to_s == '' ? ''.inspect : rmq_exchange_name
|
70
|
-
"(#{ex_name
|
70
|
+
"(#{ex_name}|#{exchange_type_code}|#{queue_name}) "
|
71
71
|
end
|
72
72
|
|
73
73
|
def request_metadata
|
@@ -19,8 +19,8 @@ module Fleck
|
|
19
19
|
@app_id = metadata[:app_id]
|
20
20
|
@reply_to = @metadata.reply_to
|
21
21
|
@payload = payload
|
22
|
-
@exchange = delivery_info.exchange
|
23
|
-
@queue = delivery_info.routing_key
|
22
|
+
@exchange = delivery_info.exchange
|
23
|
+
@queue = delivery_info.routing_key
|
24
24
|
@delivery_tag = delivery_info.delivery_tag
|
25
25
|
@data = {}
|
26
26
|
@headers = (@metadata.headers || {}).to_hash_with_indifferent_access
|
@@ -61,13 +61,24 @@ module Fleck
|
|
61
61
|
@requeue
|
62
62
|
end
|
63
63
|
|
64
|
+
def log_headers_and_params!
|
65
|
+
queue_name = "(#{@exchange == '' ? @queue : "#{@queue}@#{@exchange}"})".color(:red)
|
66
|
+
endpoint = "/#{action} :#{@version || 'v1'}".color(:red)
|
67
|
+
message = "\n" \
|
68
|
+
"#{ip} - #{queue_name} #{endpoint} [#{@id}]\n" \
|
69
|
+
" ~ headers ~ #{headers.inspect.color(:green)}\n" \
|
70
|
+
" @params #{params.inspect.color(:green)}"
|
71
|
+
logger.debug message
|
72
|
+
end
|
73
|
+
|
64
74
|
protected
|
65
75
|
|
66
76
|
def parse_request!
|
67
77
|
@data = Oj.load(@payload, mode: :compat).to_hash_with_indifferent_access.filtered!
|
68
78
|
@headers.merge!(@data['headers'] || {}).filtered!
|
69
79
|
|
70
|
-
logger.debug "
|
80
|
+
logger.debug "Request (exchange: #{@exchange.inspect}, queue: #{@queue.inspect}, " \
|
81
|
+
"options: #{@headers}, message: #{@data})"
|
71
82
|
|
72
83
|
@action ||= @headers['action']
|
73
84
|
@headers['action'] ||= @action
|
data/lib/fleck/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fleck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Groza Sergiu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|