Skip to content

Commit

Permalink
small working concept
Browse files Browse the repository at this point in the history
  • Loading branch information
maxigs committed Jan 13, 2014
1 parent b17d4a4 commit 12b40e7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/sneakers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Concerns
require 'sneakers/concerns/metrics'
require 'sneakers/handlers/oneshot'
require 'sneakers/worker'
require 'sneakers/task'
require 'sneakers/publisher'

module Sneakers
Expand Down
21 changes: 21 additions & 0 deletions lib/sneakers/task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Sneakers
module Task

def initialize(hdr, props, msg)
@hdr = hdr
@props = props
@msg = msg

@status = :new
end

def ack!
@status = :ack
end

def status
@status
end

end
end
7 changes: 5 additions & 2 deletions lib/sneakers/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def do_work(hdr, props, msg, handler)
metrics.increment("work.#{self.class.name}.started")
Timeout.timeout(@timeout_after) do
metrics.timing("work.#{self.class.name}.time") do
res = work(msg)
klass = (self.class.name + '::Task').constantize
task = klass.new(hdr, props, msg)
task.call
res = task.status
end
end
rescue Timeout::Error
Expand All @@ -62,7 +65,7 @@ def do_work(hdr, props, msg, handler)
rescue => ex
res = :error
error = ex
logger.error(ex)
logger.error "\n\nEXCEPTION: #{ex.message}\nPAYLOAD:\n#{msg.inspect}\nBACKTRACE\n#{ex.message}\n#{ex.backtrace.join("\n")}"
end

if @should_ack
Expand Down

0 comments on commit 12b40e7

Please sign in to comment.