Skip to content

Instantly share code, notes, and snippets.

@sco
Created March 26, 2009 13:14
Show Gist options
  • Save sco/86082 to your computer and use it in GitHub Desktop.
Save sco/86082 to your computer and use it in GitHub Desktop.
class WebHook < ActiveRecord::Base
class << self
# Pushes a job onto a queue
def visit!(visit)
JobQueue.new(:events).push({
:type => 'visit',
:visit_id => visit.id,
:user_id => visit.user_id,
:spot_id => visit.spot_id
})
end
# Processes a job from the queue -- safe to run in parallel
def process
JobQueue.new(:events).pop do |options|
hooks = WebHook.all(:conditions => { :event => "new_visit", :spot_id => options[:spot_id] })
hooks.each do |hook|
hook.fire(options)
end
end
end
end
def fire(options)
# make an HTTP POST...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment