class Gush::CLI::Overview

Attributes

workflow[R]

Public Class Methods

new(workflow) click to toggle source
# File lib/gush/cli/overview.rb, line 6
def initialize(workflow)
  @workflow = workflow
end

Public Instance Methods

jobs_list(jobs) click to toggle source
# File lib/gush/cli/overview.rb, line 28
def jobs_list(jobs)
  "\nJobs list:\n".tap do |output|
    jobs_by_type(jobs).each do |job|
      output << job_to_list_element(job)
    end
  end
end
status() click to toggle source
# File lib/gush/cli/overview.rb, line 14
def status
  if workflow.failed?
    failed_status
  elsif workflow.running?
    running_status
  elsif workflow.finished?
    "done".green
  elsif workflow.stopped?
    "stopped".red
  else
    "ready to start".blue
  end
end
table() click to toggle source
# File lib/gush/cli/overview.rb, line 10
def table
  Terminal::Table.new(rows: rows)
end

Private Instance Methods

columns() click to toggle source
# File lib/gush/cli/overview.rb, line 46
def columns
  {
    "ID" => workflow.id,
    "Name" => workflow.class.to_s,
    "Jobs" => workflow.jobs.count,
    "Failed jobs" => failed_jobs_count.red,
    "Succeeded jobs" => succeeded_jobs_count.green,
    "Enqueued jobs" => enqueued_jobs_count.yellow,
    "Running jobs" => running_jobs_count.blue,
    "Remaining jobs" => remaining_jobs_count,
    "Started at" => started_at,
    "Status" => status
  }
end
enqueued_jobs_count() click to toggle source
# File lib/gush/cli/overview.rb, line 130
def enqueued_jobs_count
  workflow.jobs.count(&:enqueued?).to_s
end
failed_job() click to toggle source
# File lib/gush/cli/overview.rb, line 114
def failed_job
  workflow.jobs.find(&:failed?).name
end
failed_jobs_count() click to toggle source
# File lib/gush/cli/overview.rb, line 122
def failed_jobs_count
  workflow.jobs.count(&:failed?).to_s
end
failed_status() click to toggle source
# File lib/gush/cli/overview.rb, line 71
def failed_status
  status = "failed".light_red
  status += "\n#{failed_job} failed"
end
job_to_list_element(job) click to toggle source
# File lib/gush/cli/overview.rb, line 76
def job_to_list_element(job)
  name = job.name
  case
  when job.failed?
    "[✗] #{name.red} \n"
  when job.finished?
    "[✓] #{name.green} \n"
  when job.enqueued?
    "[•] #{name.yellow} \n"
  when job.running?
    "[•] #{name.blue} \n"
  else
    "[ ] #{name} \n"
  end
end
jobs_by_type(type) click to toggle source
# File lib/gush/cli/overview.rb, line 92
def jobs_by_type(type)
  return sorted_jobs if type == :all
  jobs.select{|j| j.public_send("#{type}?") }
end
remaining_jobs_count() click to toggle source
# File lib/gush/cli/overview.rb, line 138
def remaining_jobs_count
  workflow.jobs.count{|j| [j.finished?, j.failed?, j.enqueued?].none? }.to_s
end
rows() click to toggle source
# File lib/gush/cli/overview.rb, line 37
def rows
  [].tap do |rows|
    columns.each_pair do |name, value|
      rows << [{alignment: :center, value: name}, value]
      rows << :separator if name != "Status"
    end
  end
end
running_jobs_count() click to toggle source
# File lib/gush/cli/overview.rb, line 134
def running_jobs_count
  workflow.jobs.count(&:running?).to_s
end
running_status() click to toggle source
# File lib/gush/cli/overview.rb, line 61
def running_status
  finished = succeeded_jobs_count.to_i
  status = "running".yellow
  status += "\n#{finished}/#{total_jobs_count} [#{(finished*100)/total_jobs_count}%]"
end
sorted_jobs() click to toggle source
# File lib/gush/cli/overview.rb, line 97
def sorted_jobs
  workflow.jobs.sort_by do |job|
    case
    when job.failed?
      0
    when job.finished?
      1
    when job.enqueued?
      2
    when job.running?
      3
    else
      4
    end
  end
end
started_at() click to toggle source
# File lib/gush/cli/overview.rb, line 67
def started_at
  workflow.started_at.inspect
end
succeeded_jobs_count() click to toggle source
# File lib/gush/cli/overview.rb, line 126
def succeeded_jobs_count
  workflow.jobs.count(&:succeeded?).to_s
end
total_jobs_count() click to toggle source
# File lib/gush/cli/overview.rb, line 118
def total_jobs_count
  workflow.jobs.count
end