fleck 2.0.0 → 2.1.0

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: 10ed68bc695f23ef3d185e03f57fe4c6d5a71cb890b2f550f8c84cb445330933
4
- data.tar.gz: 3dabbac45e9efa3cbc12eb5d3affa2d9a586d317df8d37d5378afd1a8c7b287f
3
+ metadata.gz: dca817403e895fd00e7d95e54d278f19e13f0941960b276b501d637c9330f588
4
+ data.tar.gz: 93e27ca7cbd491413e0fc9199c7ba259d05c2d6bef11403ee7feaf403b00453a
5
5
  SHA512:
6
- metadata.gz: 791ebf6760b8a5aea71df57a8eebe386cf5bb3a5a877a7a50f6c4a4a73a0fe89b89cd06b1c09fc8a1a8b7480aab65e96f609d61f762100f866f0454607a319cd
7
- data.tar.gz: '094dab3b65a3b0c9e1453a88339fb3e6d7f3955e26c888d02ea2aae75adde5033c7a879cf1d00249c6d5f03e4364d6d1f662ffa01093fa3f28592a78ab964c8c'
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[(rand * actions.size).to_i]
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.to_s.inspect}|#{exchange_type_code}|#{queue_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.inspect
23
- @queue = delivery_info.routing_key.inspect
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 "Processing request (exchange: #{@exchange}, queue: #{@queue}, options: #{@headers}, message: #{@data})"
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Open `Fleck` module to set `VERSION` constant.
4
4
  module Fleck
5
- VERSION = '2.0.0'
5
+ VERSION = '2.1.0'
6
6
  end
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.0.0
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-01-31 00:00:00.000000000 Z
11
+ date: 2022-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler