Class: Jobs::Job

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

Constant Summary collapse

LockedError =
Class.new(::StandardError)

Instance Method Summary collapse

Instance Method Details

#busy?Boolean

check if the job is currently being processed

e.g. status == ‘processing’ or status == ‘pending’

Returns:

  • (Boolean)


11
12
13
# File 'lib/jobs/job.rb', line 11

def busy?
  self.status != 'processing' and self.status != 'pending'
end

#instance(logger_instance, lock) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/jobs/job.rb', line 15

def instance(logger_instance, lock)
  load("#{Jobs::Root}/#{name}_job.rb")
  klass = "#{name}_job".camelize.constantize
  klass.new(self,logger_instance, lock)
rescue Object => e
  logger.error "#{e.message}\n#{e.backtrace.join("\n")}"
  return nil
end

#retryObject



24
25
26
27
28
29
# File 'lib/jobs/job.rb', line 24

def retry
  return false if locked
  self.status = 'pending'
  signal
  save
end

#retry!Object

Raises:



33
34
35
36
37
38
# File 'lib/jobs/job.rb', line 33

def retry!
  raise LockedError if locked
  self.status = 'pending'
  signal
  save!
end