Class: Chimp::ChimpDaemon::DisplayServlet

Inherits:
GenericServlet
  • Object
show all
Defined in:
lib/right_chimp/daemon/ChimpDaemon.rb

Overview

DisplayServlet

Instance Method Summary collapse

Methods inherited from GenericServlet

#get_id, #get_payload, #get_verb

Instance Method Details

#do_GET(req, resp) ⇒ Object



447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
# File 'lib/right_chimp/daemon/ChimpDaemon.rb', line 447

def do_GET(req, resp)
  #
  # First determine the path to the files to serve
  #
  if ENV['CHIMP_TEST'] != 'TRUE'
    template_path = File.join(Gem.dir, 'gems', 'right_chimp-' + VERSION, 'lib/right_chimp/templates')
  else
    template_path = 'lib/right_chimp/templates'
  end

  #
  # Check for static CSS files and serve them
  #
  if req.request_uri.path =~ /\.(css|js)$/
    filename = req.request_uri.path.split('/').last
    resp.body = File.read(File.join(template_path, filename))
    raise WEBrick::HTTPStatus::OK
  else

    #
    # Otherwise process ERB template
    #
    job_filter = self.get_verb(req) || "running"

    if not @template
      @template = ERB.new(File.read(File.join(template_path, "all_jobs.erb")), nil, ">")
    end

    queue = ChimpQueue.instance
    jobs = queue.get_jobs
    group_name = nil

    if job_filter == "group"
      group_name = req.request_uri.path.split('/')[-1]
      g = ChimpQueue[group_name.to_sym]
      jobs = g.get_jobs if g
    end

    count_jobs_running = queue.get_jobs_by_status(:running).size
    count_jobs_queued  = queue.get_jobs_by_status(:none).size
    count_jobs_holding  = queue.get_jobs_by_status(:holding).size
    count_jobs_failed  = queue.get_jobs_by_status(:error).size
    count_jobs_done    = queue.get_jobs_by_status(:done).size

    resp.body = @template.result(binding)
    raise WEBrick::HTTPStatus::OK
  end
end