Skip to content

Commit

Permalink
Complementary fix for #213. Pass body to worker_name for calls from A…
Browse files Browse the repository at this point in the history
…utoExtendVisibility
  • Loading branch information
Pablo Cantero committed Sep 2, 2016
1 parent ddf3019 commit 922449c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/shoryuken/middleware/server/auto_extend_visibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AutoExtendVisibility
EXTEND_UPFRONT_SECONDS = 5

def call(worker, queue, sqs_msg, body)
timer = auto_visibility_timer(queue, sqs_msg, worker.class)
timer = auto_visibility_timer(worker, queue, sqs_msg, body)
begin
yield
ensure
Expand All @@ -21,31 +21,32 @@ class MessageVisibilityExtender
include Celluloid
include Util

def auto_extend(queue, sqs_msg, worker_class)
def auto_extend(worker, queue, sqs_msg, body)
queue_visibility_timeout = Shoryuken::Client.queues(queue).visibility_timeout

every(queue_visibility_timeout - EXTEND_UPFRONT_SECONDS) do
begin
logger.debug do
"Extending message #{worker_name(worker_class, sqs_msg)}/#{queue}/#{sqs_msg.message_id} " \
"visibility timeout by #{queue_visibility_timeout}s."
"Extending message #{worker_name(worker.class, sqs_msg, body)}/#{queue}/#{sqs_msg.message_id} " \
"visibility timeout by #{queue_visibility_timeout}s."
end

sqs_msg.change_visibility(visibility_timeout: queue_visibility_timeout)
rescue => e
logger.error do
"Could not auto extend the message #{worker_class}/#{queue}/#{sqs_msg.message_id} " \
"visibility timeout. Error: #{e.message}"
'Could not auto extend the message ' \
"#{worker_name(worker.class, sqs_msg, body)}/#{queue}/#{sqs_msg.message_id} " \
"visibility timeout. Error: #{e.message}"
end
end
end
end
end

def auto_visibility_timer(queue, sqs_msg, worker_class)
return unless worker_class.auto_visibility_timeout?
def auto_visibility_timer(worker, queue, sqs_msg, body)
return unless worker.class.auto_visibility_timeout?
@visibility_extender ||= MessageVisibilityExtender.new_link
@visibility_extender.auto_extend(queue, sqs_msg, worker_class)
@visibility_extender.auto_extend(worker, queue, sqs_msg, body)
end
end
end
Expand Down

0 comments on commit 922449c

Please sign in to comment.