Class: Libis::Workflow::Mongoid::Job

Inherits:
Object
  • Object
show all
Includes:
Base::Job, Base
Defined in:
lib/libis/workflow/mongoid/job.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#dup, included, #to_s

Class Method Details

.from_hash(hash) ⇒ Object



32
33
34
35
36
# File 'lib/libis/workflow/mongoid/job.rb', line 32

def self.from_hash(hash)
  self.create_from_hash(hash, [:name]) do |item, cfg|
    item.workflow = Libis::Workflow::Mongoid.from_hash(name: cfg.delete(:workflow))
  end
end

Instance Method Details

#execute(opts = {}) ⇒ Object

noinspection RubyStringKeysInHashInspection



77
78
79
80
81
82
83
84
85
# File 'lib/libis/workflow/mongoid/job.rb', line 77

def execute(opts = {})
  if self.log_each_run
    opts[:run_config] = {
        'log_to_file=' => true,
        'log_level=' => self.log_level
    }
  end
  super opts
end

#logger ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/libis/workflow/mongoid/job.rb', line 55

def logger
  return ::Libis::Workflow::Mongoid::Config.logger unless self.log_to_file
  logger = ::Logging::Repository[self.name]
  return logger if logger
  unless ::Logging::Appenders[self.name]
    ::Logging::Appenders::RollingFile.new(
        self.name,
        filename: File.join(::Libis::Workflow::Mongoid::Config[:log_dir], "#{self.name}{.%Y%m%d}.log"),
        layout: ::Libis::Workflow::Mongoid::Config.get_log_formatter,
        truncate: true,
        age: self.log_age,
        keep: self.log_keep,
        roll_by: 'date',
        level: self.log_level
    )
  end
  logger = ::Libis::Workflow::Mongoid::Config.logger(self.name, self.name)
  logger.additive = false
  logger
end

#to_hash ⇒ Object



49
50
51
52
53
# File 'lib/libis/workflow/mongoid/job.rb', line 49

def to_hash
  result = super
  result[:input] = result.delete(:_input)
  result
end