Skip to content

Instantly share code, notes, and snippets.

@eric
Forked from catlike/gist:718450
Created November 28, 2010 00:59
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 eric/718455 to your computer and use it in GitHub Desktop.
Save eric/718455 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sinatra'
require 'lib/sms'
require 'thread'
SECONDS_PER_MESSAGE = 1.0
queue = Queue.new
consumer = Thread.new do
loop do
t0 = Time.now
message = queue.pop
outgoing = SMS.new
outgoing.send message['from'], message['to'], "#{message['message']} at #{Time.now}"
t1 = Time.now
diff = SECONDS_PER_MESSAGE - (t1 - t0)
sleep(diff) if diff > 0.0
end
end
post '/sms' do
content_type :json
puts "From:" + params['from']
puts "To:" + params['to']
puts "Message:" + params['message']
queue << params
puts "Queue Length:" + queue.length.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment