Sha256: 4b3a3b9094f1f3ccbba3f0283db87ab865d0145f8e760b7ebbb4bdd373af4e47
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 KB
Contents
require 'activehook/workers/base' require 'activehook/post' module ActiveHook module Workers class Queue < Base def start until @done json = retrieve_hook HookRunner.new(json) if json end end private def retrieve_hook json = ActiveHook.redis.with { |c| c.brpop('ah:queue', @time) } json.last if json end end class HookRunner def initialize(json) @hook = ActiveHook::Hook.new(JSON.parse(json)) @post = ActiveHook::POST.new(uri: @hook.uri, payload: @hook.payload) start end def start @post.start ActiveHook.redis.with do |conn| @post.success? ? hook_success(conn) : hook_failed(conn) end end private def hook_success(conn) conn.incr('ah:total_success') end def hook_failed(conn) conn.zadd('ah:retry', @hook.retry_at, @hook.to_json) if @hook.retry? conn.incr('ah:total_failed') end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activehook-0.1.0 | lib/activehook/workers/queue.rb |