Class: Actn::Jobs::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/actn/jobs/base.rb

Direct Known Subclasses

Trace

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job) ⇒ Base

Returns a new instance of Base.



11
12
13
14
# File 'lib/actn/jobs/base.rb', line 11

def initialize job
  @job = job
  @record = job.record || Oj.load(DB::Set[job.table_name].find_by({uuid: job.record_uuid}))
end

Instance Attribute Details

#jobObject

Returns the value of attribute job.



9
10
11
# File 'lib/actn/jobs/base.rb', line 9

def job
  @job
end

#recordObject

Returns the value of attribute record.



9
10
11
# File 'lib/actn/jobs/base.rb', line 9

def record
  @record
end

Instance Method Details

#performObject



16
17
# File 'lib/actn/jobs/base.rb', line 16

def perform
end

#test_and_performObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/actn/jobs/base.rb', line 19

def test_and_perform
  
  unless self.record
    $stderr.puts "[#{self.class.name}#test_and_perform, #{Time.now}]: Record not found"
    return 
  end

  if job.hook['conditions'].nil? || ( !job.hook['conditions'].map{|c| eval(c,binding) ? true : false }.include?(false) )

    run

  else
    
    Jobs.logger.warn "Conditions failed, CONDITIONS: #{job.hook['conditions']} RECORD: #{self.record}"          
    job.update(result: {error: "Conditions failed"})
    
  end
  
end