lib/sqsrun/worker.rb in sqsrun-0.5.0 vs lib/sqsrun/worker.rb in sqsrun-0.6.0

- old
+ new

@@ -12,10 +12,11 @@ @visibility_timeout = conf[:timeout] @extend_timeout = conf[:extend_timeout] @kill_timeout = conf[:kill_timeout] @kill_retry = conf[:kill_retry] @interval = conf[:interval] + @release_on_fail = conf[:release_on_fail] @finished = false @extender = TimerThread.new(@visibility_timeout, @extend_timeout, @kill_timeout, @kill_retry) @sqs = RightAws::SqsGen2.new(@key_id, @secret_key) @queue = @sqs.queue(@queue_name) @@ -76,17 +77,17 @@ end end def process(msg) puts "started id=#{msg.id}" - thread = Thread.new(msg.to_s, &@run_proc.method(:call)) @extender.set_message(msg) success = false begin - thread.join + @run_proc.call(msg.to_s) + puts "finished id=#{msg.id}" success = true rescue puts "failed id=#{msg.id}: #{$!}" $!.backtrace.each {|bt| puts " #{bt}" @@ -96,10 +97,12 @@ @extender.reset_message if success msg.delete else - msg.visibility = 0 + if @release_on_fail + msg.visibility = 0 + end end end class TimerThread include MonitorMixin