Class: Tracked::Job

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/tracked/job.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generate(job_id) ⇒ Object



5
6
7
8
# File 'lib/tracked/job.rb', line 5

def self.generate(job_id)
  uuid = SecureRandom.uuid
  self.create!(job_id: job_id, uuid: uuid)
end

Instance Method Details

#fail!(result) ⇒ Object



18
19
20
# File 'lib/tracked/job.rb', line 18

def fail!(result)
  self.update_attributes!(success: false, result: result)
end

#start!Object



10
11
12
# File 'lib/tracked/job.rb', line 10

def start!
  self.update_attributes!(started_at: Time.now)
end

#statusObject



22
23
24
25
26
27
# File 'lib/tracked/job.rb', line 22

def status
  return :created if started_at.nil?
  return :started if success.nil?
  return :success if success
  :failed
end

#succeed!(result) ⇒ Object



14
15
16
# File 'lib/tracked/job.rb', line 14

def succeed!(result)
  self.update_attributes!(success: true, result: result)
end