Class: Synco::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/synco/scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*scripts, logger: nil, verbose: false) ⇒ Runner

Returns a new instance of Runner.



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/synco/scope.rb', line 42

def initialize(*scripts, logger: nil, verbose: false)
  @scripts = scripts
  
  @logger = logger || Logger.new($stderr).tap do |logger|
    logger.formatter = CompactFormatter.new
    
    if verbose or ENV['SYNCO_VERBOSE']
      logger.level = Logger::DEBUG
    else
      logger.level = Logger::INFO
    end
  end
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



57
58
59
# File 'lib/synco/scope.rb', line 57

def logger
  @logger
end

#scriptsObject (readonly)

Returns the value of attribute scripts.



56
57
58
# File 'lib/synco/scope.rb', line 56

def scripts
  @scripts
end

Instance Method Details

#callObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/synco/scope.rb', line 59

def call
  start_time = Time.now
  
  logger.info "===== Starting at #{start_time} ====="
  
  Process::Group.wait do |group|
    @scripts.each do |script|
      Fiber.new do
        ScriptScope.new(script, @logger, group).call
      end.resume
    end
  end
ensure
  end_time = Time.now
  logger.info "[Time]: (#{end_time - start_time}s)."
  logger.info "===== Finished backup at #{end_time} ====="
end