Created
November 28, 2010 18:11
-
-
Save catlike/719144 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
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