Class: AllQ::Job
- Inherits:
-
Object
- Object
- AllQ::Job
- Defined in:
- lib/allq/job.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#client ⇒ Object
Returns the value of attribute client.
-
#expireds ⇒ Object
Returns the value of attribute expireds.
-
#id ⇒ Object
Returns the value of attribute id.
-
#releases ⇒ Object
Returns the value of attribute releases.
-
#tube ⇒ Object
Returns the value of attribute tube.
Class Method Summary collapse
Instance Method Summary collapse
- #bury ⇒ Object
- #delete ⇒ Object
- #done ⇒ Object
-
#initialize(id, client, tube = nil, body = nil, expireds = nil, releases = nil) ⇒ Job
constructor
A new instance of Job.
- #kick ⇒ Object
- #release(delay = 0) ⇒ Object
- #stats ⇒ Object
- #to_hash ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
- #touch ⇒ Object
Constructor Details
#initialize(id, client, tube = nil, body = nil, expireds = nil, releases = nil) ⇒ Job
Returns a new instance of Job.
5 6 7 8 9 10 11 12 |
# File 'lib/allq/job.rb', line 5 def initialize(id, client, tube = nil, body = nil, expireds = nil, releases = nil) @body = body @id = id @tube = tube @expireds = expireds @releases = releases @client = client end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
4 5 6 |
# File 'lib/allq/job.rb', line 4 def body @body end |
#client ⇒ Object
Returns the value of attribute client.
4 5 6 |
# File 'lib/allq/job.rb', line 4 def client @client end |
#expireds ⇒ Object
Returns the value of attribute expireds.
4 5 6 |
# File 'lib/allq/job.rb', line 4 def expireds @expireds end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/allq/job.rb', line 4 def id @id end |
#releases ⇒ Object
Returns the value of attribute releases.
4 5 6 |
# File 'lib/allq/job.rb', line 4 def releases @releases end |
#tube ⇒ Object
Returns the value of attribute tube.
4 5 6 |
# File 'lib/allq/job.rb', line 4 def tube @tube end |
Class Method Details
.new_from_hash(hash, client) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/allq/job.rb', line 66 def self.new_from_hash(hash, client) begin id = hash.fetch('job_id') body = hash.fetch('body') tube = hash.fetch('tube') expireds = hash.fetch('expireds') releases = hash.fetch('releases') job = Job.new(id, client, tube, body, expireds, releases) return job rescue => ex puts caller puts "Server value: #{hash}" puts "Can't create job, version mismatch?" puts "Invalid job data #{ex.}" end end |
Instance Method Details
#bury ⇒ Object
44 45 46 |
# File 'lib/allq/job.rb', line 44 def bury @client.bury(self) end |
#delete ⇒ Object
28 29 30 |
# File 'lib/allq/job.rb', line 28 def delete @client.delete(self) end |
#done ⇒ Object
24 25 26 |
# File 'lib/allq/job.rb', line 24 def done @client.done(self) end |
#kick ⇒ Object
36 37 38 |
# File 'lib/allq/job.rb', line 36 def kick @client.kick(self) end |
#release(delay = 0) ⇒ Object
40 41 42 |
# File 'lib/allq/job.rb', line 40 def release(delay = 0) @client.release(self, delay) end |
#stats ⇒ Object
59 60 61 62 63 64 |
# File 'lib/allq/job.rb', line 59 def stats { "releases" => @releases, "expireds" => @expireds } end |
#to_hash ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/allq/job.rb', line 14 def to_hash { 'job_id' => @id, 'body' => @body, 'tube' => @tube, 'expireds' => @expireds, 'releases' => @releases } end |
#to_json ⇒ Object
48 49 50 51 52 53 |
# File 'lib/allq/job.rb', line 48 def to_json { id: @id, body: @body } end |
#to_s ⇒ Object
55 56 57 |
# File 'lib/allq/job.rb', line 55 def to_s to_json.to_json end |
#touch ⇒ Object
32 33 34 |
# File 'lib/allq/job.rb', line 32 def touch @client.touch(self) end |