Class: Tumugi::Command::Run

Inherits:
Object
  • Object
show all
Includes:
Mixin::Listable
Defined in:
lib/tumugi/command/run.rb

Instance Method Summary collapse

Methods included from Mixin::Listable

#list

Instance Method Details

#execute(dag, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/tumugi/command/run.rb', line 13

def execute(dag, options={})
  workers = options[:workers] || Tumugi.config.workers
  settings = { in_threads: workers }
  logger = Tumugi.logger

  Parallel.each(dag.tsort, settings) do |t|
    logger.info "start: #{t.id}"
    until t.ready? || t.requires_failed?
      sleep 1
    end

    if t.completed?
      t.state = :skipped
      logger.info "#{t.state}: #{t.id} is already completed"
    elsif t.requires_failed?
      t.state = :requires_failed
      logger.info "#{t.state}: #{t.id} has failed requires task"
    else
      logger.info "run: #{t.id}"
      t.state = :running

      begin
        Retriable.retriable retry_options do
          t.run
        end
      rescue => e
        t.state = :failed
        logger.info "#{t.state}: #{t.id}"
        logger.error "#{e.message}"
      else
        t.state = :completed
        logger.info "#{t.state}: #{t.id}"
      end
    end
  end

  show_result_report(dag)
  return !dag.tsort.any? { |t| t.state == :failed }
end