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 +4 -4
- data/lib/leveret/queue.rb +2 -1
- data/lib/leveret/version.rb +1 -1
- data/lib/leveret/worker.rb +9 -6
- data/lib/leveret.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ad5d86c738d44521e7c94d660a85cd7146c6934
|
4
|
+
data.tar.gz: 4df57359cff0b01b6dd58d71b0b5a10962e605c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/lib/leveret/version.rb
CHANGED
data/lib/leveret/worker.rb
CHANGED
@@ -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, :
|
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