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

included, #to_hash, #to_s

Class Method Details

.from_hash(hash) ⇒ Object



37
38
39
40
41
# File 'lib/libis/workflow/mongoid/job.rb', line 37

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

Instance Method Details

#execute(opts = {}) ⇒ Object

noinspection RubyStringKeysInHashInspection



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/libis/workflow/mongoid/job.rb', line 65

def execute(opts = {})
  opts['run_config'] ||= {}
  if self.log_each_run
    opts['run_config']['log_to_file'] = true
    opts['run_config']['log_level'] = self.log_level
  end
  if (run_name = opts.delete('run_name'))
    opts['run_config']['run_name'] = run_name
  end
  super opts
end

#loggerObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/libis/workflow/mongoid/job.rb', line 43

def logger
  return ::Libis::Workflow::Mongoid::Config.logger unless self.log_to_file
  logger = ::Logging::Repository.instance[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