Class: Flaky::Commands::Fetch

Inherits:
Object
  • Object
show all
Defined in:
lib/flaky/commands/fetch.rb

Instance Method Summary collapse

Constructor Details

#initialize(age: "24h") ⇒ Fetch

Returns a new instance of Fetch.



9
10
11
12
13
# File 'lib/flaky/commands/fetch.rb', line 9

def initialize(age: "24h")
  @age = age
  @repo = Repository.new
  @parser = LogParser.new
end

Instance Method Details

#executeObject



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
# File 'lib/flaky/commands/fetch.rb', line 15

def execute
  provider = Flaky.provider
  branch = Flaky.configuration.branch

  print "Fetching #{branch} workflows (last #{@age})... "
  $stdout.flush
  workflows = provider.fetch_workflows(age: @age)
  puts "#{workflows.length} found."

  if workflows.empty?
    puts "Nothing to do."
    return
  end

  new_workflows = workflows.reject { |wf| @repo.workflow_fetched?(wf[:id]) }

  if new_workflows.empty?
    puts "All #{workflows.length} workflows already in database."
    return
  end

  puts "Processing #{new_workflows.length} new workflow(s)..."

  total_jobs = 0
  total_failures = 0

  new_workflows.each_with_index do |wf, wi|
    jobs, failures = process_workflow(provider, wf, wi, new_workflows.length)
    total_jobs += jobs
    total_failures += failures
  end

  puts "\nDone: #{new_workflows.length} workflow(s), #{total_jobs} job(s), #{total_failures} failure(s) recorded."
ensure
  @repo.close
end