leveret 0.1.3 → 0.1.4

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
  SHA1:
3
- metadata.gz: 3ae4cf9c9235692a5e6db6cca5207cf66bed135e
4
- data.tar.gz: fce119a83493fcf6da93b56cfaa5f2fc1ae7d379
3
+ metadata.gz: 6ad5d86c738d44521e7c94d660a85cd7146c6934
4
+ data.tar.gz: 4df57359cff0b01b6dd58d71b0b5a10962e605c6
5
5
  SHA512:
6
- metadata.gz: 67115f963e00f086452dd6e31bc6eb938f95d563dc5f422c29198689b0edb83210ea02e4329233e848a738e69f5921824c55c8578d2ea3ee26d217bcbb528d04
7
- data.tar.gz: c329e5873ecb87468cd67c9df9bc950afd8fe13e221cc240c1833c52b6a44e0e03d386742915ead87703aae46bffcba375dfbb9da6e6cdd7883c96260598de06
6
+ metadata.gz: 4bcc8fe946aa915c5ab765a6b8cd99ead0e2254ccc88ac4852de110543d7afff7465674d5facf604c7addff393c52cea17c36b38869873778bce864d0264825e
7
+ data.tar.gz: 1c2033a0b4b61b3147551744f67f4e8a09dfedd09d6f66c9204a9e816f209ed285cc13fa4a08c9c5bb157b4ca7ddaedeb7cf395059e89c19e12834f259579fc4
data/lib/leveret/queue.rb CHANGED
@@ -53,6 +53,7 @@ module Leveret
53
53
  #
54
54
  # @note The receiving block is responsible for acking/rejecting the message. Please see the note for more details.
55
55
  #
56
+ # @yieldparam channel [Bunny::Channel] RabbitMQ channel receiver should use to send ack/reject
56
57
  # @yieldparam delivery_tag [String] The identifier for this message that must be used do ack/reject the message
57
58
  # @yieldparam payload [Parameters] A deserialized version of the payload contained in the message
58
59
  #
@@ -61,7 +62,7 @@ module Leveret
61
62
  log.info "Subscribing to #{name}"
62
63
  queue.subscribe(manual_ack: true) do |delivery_info, _properties, msg|
63
64
  log.debug "Received #{msg} from #{name}"
64
- yield(delivery_info.delivery_tag, deserialize_payload(msg))
65
+ yield(queue.channel, delivery_info.delivery_tag, deserialize_payload(msg))
65
66
  end
66
67
  end
67
68
 
@@ -1,3 +1,3 @@
1
1
  module Leveret
2
- VERSION = "0.1.3".freeze
2
+ VERSION = "0.1.4".freeze
3
3
  end
@@ -11,7 +11,7 @@ module Leveret
11
11
  # @return [Array<Bunny::Consumer>] All of the actively subscribed queues
12
12
  attr_accessor :queues, :consumers
13
13
 
14
- def_delegators :Leveret, :log, :channel, :configuration
14
+ def_delegators :Leveret, :log, :configuration
15
15
 
16
16
  # Create a new worker to process jobs from the list of queue names passed
17
17
  #
@@ -69,8 +69,8 @@ module Leveret
69
69
  # allow us to gracefully cancel these subscriptions when we need to quit.
70
70
  def start_subscriptions
71
71
  queues.map do |queue|
72
- consumers << queue.subscribe do |delivery_tag, payload|
73
- fork_and_run(delivery_tag, payload)
72
+ consumers << queue.subscribe do |channel, delivery_tag, payload|
73
+ fork_and_run(channel, delivery_tag, payload)
74
74
  end
75
75
  end
76
76
  end
@@ -88,19 +88,21 @@ module Leveret
88
88
  # Detach the main process from the child so we can return to the main loop without waiting for it to finish
89
89
  # processing the job.
90
90
  #
91
+ # @param [Bunny::Channel] channel RabbitMQ channel to send the ack message on
91
92
  # @param [String] delivery_tag The identifier that RabbitMQ uses to track the message. This will be used to ack
92
93
  # or reject the message after processing.
93
94
  # @param [Parameters] payload The job name and parameters the job requires
94
- def fork_and_run(delivery_tag, payload)
95
+ def fork_and_run(channel, delivery_tag, payload)
95
96
  pid = fork do
96
97
  self.process_name = 'leveret-worker-child'
97
98
  log.info "[#{delivery_tag}] Forked to child process #{pid} to run #{payload[:job]}"
98
99
 
100
+ Leveret.reset_connection!
99
101
  Leveret.configuration.after_fork.call
100
102
 
101
103
  result = perform_job(payload)
102
104
  log.info "[#{delivery_tag}] Job returned #{result}"
103
- ack_message(delivery_tag, result)
105
+ ack_message(channel, delivery_tag, result)
104
106
 
105
107
  log.info "[#{delivery_tag}] Exiting child process #{pid}"
106
108
  exit!(0)
@@ -121,10 +123,11 @@ module Leveret
121
123
 
122
124
  # Sends a message back to RabbitMQ confirming the completed execution of the message
123
125
  #
126
+ # @param [Bunny::Channel] channel RabbitMQ channel to send the ack message on
124
127
  # @param [String] delivery_tag The identifier that RabbitMQ uses to track the message. This will be used to ack
125
128
  # or reject the message after processing.
126
129
  # @param [Symbol] result :success, :reject or :requeue depending on how we want to acknowledge the message
127
- def ack_message(delivery_tag, result)
130
+ def ack_message(channel, delivery_tag, result)
128
131
  if result == :reject
129
132
  log.debug "[#{delivery_tag}] Rejecting message"
130
133
  channel.reject(delivery_tag)
data/lib/leveret.rb CHANGED
@@ -54,6 +54,11 @@ module Leveret
54
54
  end
55
55
  end
56
56
 
57
+ def reset_connection!
58
+ @mq_connection = nil
59
+ @channel = nil
60
+ end
61
+
57
62
  # Logger used throughout Leveret, see {Configuration} for config options.
58
63
  #
59
64
  # @return [Logger] Standard ruby logger
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leveret
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Wentworth