Class: Reqless::ClientJobs

Inherits:
Object
  • Object
show all
Defined in:
lib/reqless.rb

Overview

A class for interacting with jobs. Not meant to be instantiated directly, it’s accessed through Client#jobs

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ClientJobs

Returns a new instance of ClientJobs.



45
46
47
# File 'lib/reqless.rb', line 45

def initialize(client)
  @client = client
end

Instance Method Details

#[](id) ⇒ Object



76
77
78
# File 'lib/reqless.rb', line 76

def [](id)
  get(id)
end

#complete(offset = 0, count = 25) ⇒ Object



49
50
51
# File 'lib/reqless.rb', line 49

def complete(offset = 0, count = 25)
  JSON.parse(@client.call('jobs.completed', offset, count))
end

#failed(t = nil, start = 0, limit = 25) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/reqless.rb', line 66

def failed(t = nil, start = 0, limit = 25)
  if !t
    return JSON.parse(@client.call('failureGroups.counts'))
  else
    results = JSON.parse(@client.call('jobs.failedByGroup', t, start, limit))
    results['jobs'] = multiget(*results['jobs'])
    results
  end
end

#get(jid) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/reqless.rb', line 80

def get(jid)
  results = @client.call('job.get', jid)
  if results.nil?
    results = @client.call('recurringJob.get', jid)
    return nil if results.nil?
    return RecurringJob.new(@client, JSON.parse(results))
  end
  Job.new(@client, JSON.parse(results))
end

#multiget(*jids) ⇒ Object



90
91
92
93
94
95
# File 'lib/reqless.rb', line 90

def multiget(*jids)
  results = JSON.parse(@client.call('job.getMulti', *jids))
  results.map do |data|
    Job.new(@client, data)
  end
end

#tagged(tag, offset = 0, count = 25) ⇒ Object



59
60
61
62
63
64
# File 'lib/reqless.rb', line 59

def tagged(tag, offset = 0, count = 25)
  results = JSON.parse(@client.call('jobs.tagged', tag, offset, count))
  # Should be an empty array instead of an empty hash
  results['jobs'] = [] if results['jobs'] == {}
  results
end

#trackedObject



53
54
55
56
57
# File 'lib/reqless.rb', line 53

def tracked
  results = JSON.parse(@client.call('jobs.tracked'))
  results['jobs'] = results['jobs'].map { |j| Job.new(@client, j) }
  results
end