Sha256: 9759b4065536ee3fa59ce651bc9174da424c3d1a501d73bae057534725d73b1f

Contents?: true

Size: 944 Bytes

Versions: 1

Compression:

Stored size: 944 Bytes

Contents

require "json"
require "multi_json"
require "sinatra"
require "sinatra/json"
require File.dirname(__FILE__) + '/log'
require File.dirname(__FILE__) + '/queue'

queue = WorkerArmy::Queue.new

get '/' do
  job_count = queue.get_job_count || 0
  workers = queue.get_known_workers
  last_ping = queue.last_ping || 0
  queues = queue.get_known_queues
  finished_jobs = queue.finished_jobs
  failed_jobs = queue.failed_jobs
  data = { job_count: job_count, finished_jobs: finished_jobs,
    failed_jobs: failed_jobs, workers: workers,
    last_worker_ping: last_ping.to_i, queues: queues
  }
  json data
end

post '/jobs' do
  data = JSON.parse(request.body.read)
  queue_job = queue.push data if data
  json queue_job
end

post '/callback' do
  data = JSON.parse(request.body.read)
  queue.save_result(data) if data
  json data
end

post '/generic_callback' do
  data = JSON.parse(request.body.read)
  status = { :status => 'ok' }
  json status
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
worker-army-0.3.2 lib/worker_army/web.rb