Class: Reqless::ClientJobs
- Inherits:
-
Object
- Object
- Reqless::ClientJobs
- 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
- #[](id) ⇒ Object
- #complete(offset = 0, count = 25) ⇒ Object
- #failed(t = nil, start = 0, limit = 25) ⇒ Object
- #get(jid) ⇒ Object
-
#initialize(client) ⇒ ClientJobs
constructor
A new instance of ClientJobs.
- #multiget(*jids) ⇒ Object
- #tagged(tag, offset = 0, count = 25) ⇒ Object
- #tracked ⇒ Object
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 |