Created
November 23, 2012 19:19
-
-
Save kkuchta/4136909 to your computer and use it in GitHub Desktop.
Simple job server
This file contains 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 'sinatra' | |
jobs = Hash.new | |
get '/' do | |
<<-eos | |
Usage:<br /> | |
/getJob/<jobType><br /> | |
/addJob/<jobType>/<jobInfo><br /> | |
/showJobs<br /> | |
eos | |
end | |
get '/getJob/:jobType' do | |
jobType = params[:jobType] | |
logger.info( "waiting on job type " + jobType ) | |
sleep(1) until jobs[jobType] != nil and jobs[jobType].length > 0 | |
"Got job of type " + jobType + " with job data " + jobs[jobType].shift | |
end | |
get '/addJob/:jobType/:jobInfo' do | |
jobType = params[:jobType] | |
jobs[jobType] = Array.new if jobs[jobType] == nil | |
jobs[jobType].push params[:jobInfo] | |
"job added" | |
end | |
get '/showJobs' do | |
output = '<ul>' | |
jobs.keys.each do |jobType| | |
output += '<li>' + jobType + '</li>' | |
output += '<ul>' | |
jobs[jobType].each do |jobInfo| | |
output += '<li>' + jobInfo.to_s + '</li>' | |
end | |
output += '</ul>' | |
end | |
output += '</ul>' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment