-
-
Save kastner/86186 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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