Class: Libis::Workflow::Mongoid::Run

Inherits:
WorkItem
  • Object
show all
Includes:
Base::Run
Defined in:
lib/libis/workflow/mongoid/run.rb

Instance Method Summary collapse

Methods inherited from WorkItem

#add_item, #copy_item, #get_item_list, #get_items, #move_item

Methods included from Base

included, #to_hash, #to_s

Instance Method Details

#close_loggerObject



78
79
80
81
82
83
# File 'lib/libis/workflow/mongoid/run.rb', line 78

def close_logger
  return unless self.log_to_file
  ::Logging::Appenders[self.name].close
  ::Logging::Appenders.remove(self.name)
  ::Logging::Repository.instance.delete(self.name)
end

#loggerObject



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

def logger
  unless self.log_to_file
    return self.job.logger
  end
  logger = ::Logging::Repository.instance[self.name]
  return logger if logger
  unless ::Logging::Appenders[self.name]
    self.log_filename ||= File.join(::Libis::Workflow::Mongoid::Config[:log_dir], "#{self.name}-#{self.id}.log")
    ::Logging::Appenders::File.new(
        self.name,
        filename: self.log_filename,
        layout: ::Libis::Workflow::Mongoid::Config.get_log_formatter,
        level: self.log_level
    )
  end
  logger = ::Libis::Workflow::Mongoid::Config.logger(self.name, self.name)
  logger.additive = false
  logger.level = self.log_level
  logger
end

#nameObject



85
86
87
88
89
90
91
92
93
# File 'lib/libis/workflow/mongoid/run.rb', line 85

def name
  parts = [self.job.name]
  parts << self.run_name unless self.run_name.blank?
  parts << self.id.generation_time.strftime('%Y%m%d-%H%M%S')
  parts << self.id.to_s[8..-1] if self.run_name.blank?
  parts.join('-')
rescue
  self.id.to_s
end

#rm_logObject



31
32
33
34
# File 'lib/libis/workflow/mongoid/run.rb', line 31

def rm_log
  log_file = self.log_filename
  FileUtils.rm(log_file) if log_file && !log_file.blank? && File.exist?(log_file)
end

#rm_workdirObject



36
37
38
39
# File 'lib/libis/workflow/mongoid/run.rb', line 36

def rm_workdir
  workdir = self.work_dir
  FileUtils.rmtree workdir if workdir && !workdir.blank? && Dir.exist?(workdir)
end

#run(action = :run) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/libis/workflow/mongoid/run.rb', line 48

def run(action = :run)
  self.start_date = Time.now
  self.tasks = []
  super action
  self.reload
  self.reload_relations
  close_logger
end

#work_dirObject



41
42
43
44
45
46
# File 'lib/libis/workflow/mongoid/run.rb', line 41

def work_dir
  # noinspection RubyResolve
  dir = File.join(Libis::Workflow::Config.workdir, self.id)
  FileUtils.mkpath dir unless Dir.exist?(dir)
  dir
end