class Chimp::ChimpDaemon::GroupServlet

GroupServlet - group information and control

localhost:9055/group/default/running

Public Instance Methods

do_GET(req, resp) click to toggle source

GET a group by name and status /group/<name>/<status>

# File lib/right_chimp/daemon/chimp_daemon.rb, line 343
def do_GET(req, resp)

  jobs = []
  Log.debug 'get group info'

  group_name = req.request_uri.path.split('/')[-2]
  filter     = req.request_uri.path.split('/')[-1]
  # Quickly check processing jobs just in case
  # Instance the entire queue
  q = ChimpQueue.instance
  g2 = q.processing[group_name.to_sym]

  if g2
    Log.debug 'Found processing job(s): ' + g2.inspect
  else
    Log.debug 'not found any processing jobs for that group: ' + g2.inspect
  end

  g = ChimpQueue[group_name.to_sym]
  raise WEBrick::HTTPStatus::NotFound, 'Group not found' unless g || g2
  jobs = g.get_jobs_by_status(filter) if g

  # If there are processing jobs, add them as dummy executions.
  if g2 && !g2.empty?

    Log.debug 'Group: ' + group_name + ' is processing:'
    g2.each do |job|
      Log.debug 'Job: ' + job.to_s
      j = ExecRightScript.new(group: group_name, job_uuid: job)
      jobs.push j
    end
  end

  resp.body = jobs.to_yaml

  raise WEBrick::HTTPStatus::OK
end
do_POST(req, resp) click to toggle source

POST to a group to trigger a group action /group/<name>/<action>

# File lib/right_chimp/daemon/chimp_daemon.rb, line 385
def do_POST(req, resp)
  group_name = req.request_uri.path.split('/')[-2]
  filter     = req.request_uri.path.split('/')[-1]
  payload    = self.get_payload(req)

  if filter == 'create'
    ChimpQueue.instance.create_group(group_name, payload['type'], payload['concurrency'])
  elsif filter == 'retry'
    group = ChimpQueue[group_name.to_sym]
    raise WEBrick::HTTPStatus::NotFound, "Group not found" unless group

    group.requeue_failed_jobs!
    raise WEBrick::HTTPStatus::OK

  else
    raise WEBrick::HTTPStatus::PreconditionFailed.new("invalid action")
  end
end