ack simple messages before executing the handler logic
MODIFY
lib/beetle/message.rb
lib/beetle/message.rb
@@ -293,13 +293,12 @@ module Beetle
ack!
RC::Ancient
elsif simple?
+ ack!
if @store.setnx_completed!(msg_id)
- rc = run_handler(handler) == RC::HandlerCrash ? RC::AttemptsLimitReached : RC::OK
+ run_handler(handler) == RC::HandlerCrash ? RC::AttemptsLimitReached : RC::OK
else
- rc = RC::OK
+ RC::OK
end
- ack!
- rc
elsif !key_exists?
run_handler!(handler)
else

MODIFY
test/beetle/message_test.rb
test/beetle/message_test.rb
@@ -313,8 +313,8 @@ module Beetle
handler = mock("handler")
s = sequence("s")
handler.expects(:pre_process).with(message).in_sequence(s)
- handler.expects(:call).in_sequence(s)
header.expects(:ack).in_sequence(s)
+ handler.expects(:call).in_sequence(s)
assert_equal RC::OK, message.process(handler)
end
@@ -325,9 +325,9 @@ module Beetle
handler = mock("handler")
s = sequence("s")
handler.expects(:pre_process).with(message).in_sequence(s)
+ header.expects(:ack).in_sequence(s)
e = Exception.new("ohoh")
handler.expects(:call).in_sequence(s).raises(e)
- header.expects(:ack).in_sequence(s)
handler.expects(:process_exception).with(e).in_sequence(s)
handler.expects(:process_failure).with(RC::AttemptsLimitReached).in_sequence(s)
assert_equal RC::AttemptsLimitReached, message.process(handler)

ack simple messages before executing the handler logic