Created
October 12, 2012 07:59
-
-
Save oogali/3877868 to your computer and use it in GitHub Desktop.
crazy.
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
# run rackup -s thin | |
# | |
require 'queue-stuffs' | |
map '/' do | |
run Herro | |
end |
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 'json' | |
require 'time' | |
class Herro < Sinatra::Application | |
def initialize | |
@queue = {} | |
super | |
end | |
get '/' do | |
JSON.pretty_generate @queue | |
end | |
get '/add/:delay/:key/:value' do |delay, key, value| | |
return "Sorry, key #{key} already exists.\n" if @queue.has_key? key | |
@queue[key] = EM::Timer.new delay.to_i do | |
puts Time.now | |
puts "#{key}: #{value}" | |
@queue.delete key | |
end | |
"Added #{key} to queue, with a #{delay.to_i}-second delay" | |
end | |
end | |
h = Herro.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment