Skip to content

Instantly share code, notes, and snippets.

@akahn
Last active January 28, 2016 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akahn/2e933d26bd996a2ec74e to your computer and use it in GitHub Desktop.
Save akahn/2e933d26bd996a2ec74e to your computer and use it in GitHub Desktop.
[Producer.new(pool, notifications_east, Notifier).thread,
Producer.new(pool, notifications_west, Annotator).thread,
Producer.new(pool, annotations_east, Annotator).thread,
Producer.new(pool, annotations_west, Annotator).thread].each &:join
class Producer
def initialize(pool, queue, work_class)
@pool = pool
@queue = queue
@work_class = work_class
end
def post_work
message = @queue.receive_message({attributes: [:all], wait_time_seconds: 15})
@pool.post do
begin
@work_class.new(message).process_message
rescue => e
Rails.logger.warn "Exception while processing job: #{e}\n#{e.backtrace}"
end
end
end
def run
loop { post_work }
end
def thread
Thread.new { run }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment