Class: Chimp::ChimpDaemon::GroupServlet

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

Overview

GroupServlet - group information and control

localhost:9055/group/default/running

Instance Method Summary collapse

Methods inherited from GenericServlet

#get_id, #get_job_uuid, #get_payload, #get_verb

Instance Method Details

#do_GET(req, resp) ⇒ Object

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

Raises:

  • (WEBrick::HTTPStatus::NotFound)


339
340
341
342
343
344
345
346
347
348
349
# File 'lib/right_chimp/daemon/ChimpDaemon.rb', line 339

def do_GET(req, resp)
  jobs = {}

  group_name = req.request_uri.path.split('/')[-2]
  filter     = req.request_uri.path.split('/')[-1]
  g = ChimpQueue[group_name.to_sym]
  raise WEBrick::HTTPStatus::NotFound, "Group not found" unless g
  jobs = g.get_jobs_by_status(filter)
  resp.body = jobs.to_yaml
  raise WEBrick::HTTPStatus::OK
end

#do_POST(req, resp) ⇒ Object

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



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/right_chimp/daemon/ChimpDaemon.rb', line 355

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