Skip to content

Instantly share code, notes, and snippets.

@linuxsable
Created August 20, 2010 07:41
Show Gist options
  • Select an option

  • Save linuxsable/539835 to your computer and use it in GitHub Desktop.

Select an option

Save linuxsable/539835 to your computer and use it in GitHub Desktop.
post '/messages_async' do
Thread.new(params[:data]) do |params_data|
data = JSON.parse(params_data)
channel_name = data['channel'] || 'boo'
message = data['message'] || nil
if record = Channel.first(:name => channel_name)
if message and record.id
subscribers = Subscriber.all(:channel_id => record.id)
if subscribers
max_trys = 3
trys = max_trys
subscribers.each do |sub|
# Start sending out the messages to subscribers
while trys > 0
begin
resp = RestClient.post(sub.url, :data => message)
break
rescue => e
trys -= 1
end
if trys == 0
# Couldn't send message
end
end
end
end
end
end
end
return { :status => 'OK' }.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment