Class: Qless::ClientJobs
- Inherits:
-
Object
- Object
- Qless::ClientJobs
- Defined in:
- lib/qless.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.
53 54 55 |
# File 'lib/qless.rb', line 53 def initialize(client) @client = client end |
Instance Method Details
#[](id) ⇒ Object
84 85 86 |
# File 'lib/qless.rb', line 84 def [](id) get(id) end |
#complete(offset = 0, count = 25) ⇒ Object
57 58 59 |
# File 'lib/qless.rb', line 57 def complete(offset = 0, count = 25) @client.call('jobs', 'complete', offset, count) end |
#failed(t = nil, start = 0, limit = 25) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/qless.rb', line 74 def failed(t = nil, start = 0, limit = 25) if !t return JSON.parse(@client.call('failed')) else results = JSON.parse(@client.call('failed', t, start, limit)) results['jobs'] = multiget(*results['jobs']) results end end |
#get(jid) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/qless.rb', line 88 def get(jid) results = @client.call('get', jid) if results.nil? results = @client.call('recur.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
98 99 100 101 102 103 |
# File 'lib/qless.rb', line 98 def multiget(*jids) results = JSON.parse(@client.call('multiget', *jids)) results.map do |data| Job.new(@client, data) end end |
#tagged(tag, offset = 0, count = 25) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/qless.rb', line 67 def tagged(tag, offset = 0, count = 25) results = JSON.parse(@client.call('tag', 'get', tag, offset, count)) # Should be an empty array instead of an empty hash results['jobs'] = [] if results['jobs'] == {} results end |