Class: Chimp::ChimpDaemon::GroupServlet

Inherits:
GenericServlet
  • Object
show all
Defined in:
lib/right_chimp/daemon/chimp_daemon.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)


343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# 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) ⇒ Object

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



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# 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