Skip to content

Instantly share code, notes, and snippets.

@oogali
Created October 12, 2012 07:59
Show Gist options
  • Save oogali/3877868 to your computer and use it in GitHub Desktop.
Save oogali/3877868 to your computer and use it in GitHub Desktop.
crazy.
# run rackup -s thin
#
require 'queue-stuffs'
map '/' do
run Herro
end
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