Class: Dag::JobCollection

Inherits:
Model
  • Object
show all
Includes:
Client::JobValidation, Enumerable
Defined in:
lib/dag/client/model/job_collection.rb

Constant Summary

Constants included from Client::JobValidation

Client::JobValidation::VALID_WHERE_KEYS

Instance Attribute Summary

Attributes inherited from Model

#api

Instance Method Summary collapse

Methods included from Client::JobValidation

#validate_job_param_keys

Constructor Details

#initialize(api) ⇒ JobCollection

Returns a new instance of JobCollection.



6
7
8
# File 'lib/dag/client/model/job_collection.rb', line 6

def initialize(api)
  super(api)
end

Instance Method Details

#eachObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dag/client/model/job_collection.rb', line 48

def each
  if @limit
    count, i = 0, 0
    total = @max ? @max.inject(:+) : @limit
  end

  marker = nil
  truncated = false
  begin
    @limit = @max[i] if @max
    job_info_list = @api.query_info_list(make_options(marker))
    job_info_list['queries'].each do |job_info|
      yield Dag::Job.new(@api, job_info)
    end
    truncated = job_info_list['isTruncated']
    marker = job_info_list['nextMarker']

    if @limit
      i += 1
      count += @limit
      break if total <= count
    end
  end while truncated
end

#limit(number = 100) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dag/client/model/job_collection.rb', line 33

def limit(number = 100)
  @limit = number.to_i
  max = 100

  if number > max
    @max = []
    (number / max).times { @max << max }
    if rem = (number % max)
      @max << rem if rem != 0
    end
  end

  self
end

#order(o) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/dag/client/model/job_collection.rb', line 22

def order(o)
  result = o.downcase.to_s
  unless ['asc', 'desc'].include?(result)
    raise Dag::Client::ParameterInvalid.new("Invalid order condition: #{o}")
  end

  @order = result

  self
end

#where(params = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dag/client/model/job_collection.rb', line 10

def where(params = {})
  validate_job_param_keys(params)

  @status = params[:status] if params[:status].present?
  @type = params[:type] if params[:type].present?
  @cluster_name = params[:cluster_name] if params[:cluster_name].present?
  @label = params[:label] if params[:label].present?
  @cluster_rebooted = params[:cluster_rebooted]

  self
end