Class: AllQ::Job

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#bodyObject

Returns the value of attribute body.



4
5
6
# File 'lib/allq/job.rb', line 4

def body
  @body
end

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/allq/job.rb', line 4

def client
  @client
end

#expiredsObject

Returns the value of attribute expireds.



4
5
6
# File 'lib/allq/job.rb', line 4

def expireds
  @expireds
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/allq/job.rb', line 4

def id
  @id
end

#releasesObject

Returns the value of attribute releases.



4
5
6
# File 'lib/allq/job.rb', line 4

def releases
  @releases
end

#tubeObject

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.message}"
  end


end

Instance Method Details

#buryObject



44
45
46
# File 'lib/allq/job.rb', line 44

def bury
  @client.bury(self)
end

#deleteObject



28
29
30
# File 'lib/allq/job.rb', line 28

def delete
  @client.delete(self)
end

#doneObject



24
25
26
# File 'lib/allq/job.rb', line 24

def done
  @client.done(self)
end

#kickObject



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

#statsObject



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

def stats
  {
    "releases" => @releases,
    "expireds" => @expireds
  }
end

#to_hashObject



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_jsonObject



48
49
50
51
52
53
# File 'lib/allq/job.rb', line 48

def to_json
  {
    id: @id,
    body: @body
  }
end

#to_sObject



55
56
57
# File 'lib/allq/job.rb', line 55

def to_s
  to_json.to_json
end

#touchObject



32
33
34
# File 'lib/allq/job.rb', line 32

def touch
  @client.touch(self)
end