class Gush::CLI

Public Class Methods

new(*) click to toggle source
Calls superclass method
# File lib/gush/cli.rb, line 18
def initialize(*)
  super
  Gush.configure do |config|
    config.gushfile    = options.fetch("gushfile",    config.gushfile)
    config.concurrency = options.fetch("concurrency", config.concurrency)
    config.redis_url   = options.fetch("redis",       config.redis_url)
    #config.namespace   = options.fetch("namespace",   config.namespace)

    config.redis_prefix   = options.fetch('redis_prefix', config.redis_prefix)
    config.sidekiq_queue   = options.fetch('sidekiq_queue', config.sidekiq_queue)

    config.environment = options.fetch("environment", config.environment)
  end
  load_gushfile
end

Public Instance Methods

clear() click to toggle source
# File lib/gush/cli.rb, line 62
def clear
  #Sidekiq::Queue.new(client.configuration.namespace).clear
  Sidekiq::Queue.new(client.configuration.sidekiq_queue).clear
end
create(name) click to toggle source
# File lib/gush/cli.rb, line 35
def create(name)
  workflow = client.create_workflow(name)
  puts "Workflow created with id: #{workflow.id}"
  puts "Start it with command: gush start #{workflow.id}"
end
create_and_start(name, *args) click to toggle source
# File lib/gush/cli.rb, line 49
def create_and_start(name, *args)
  workflow = client.create_workflow(name)
  client.start_workflow(workflow.id, args)
  puts "Created and started workflow with id: #{workflow.id}"
end
list() click to toggle source
# File lib/gush/cli.rb, line 86
def list
  workflows = client.all_workflows
  rows = workflows.map do |workflow|
    [workflow.id, workflow.class, {alignment: :center, value: status_for(workflow)}]
  end
  headers = [
    {alignment: :center, value: 'id'},
    {alignment: :center, value: 'name'},
    {alignment: :center, value: 'status'}
  ]
  puts Terminal::Table.new(headings: headers, rows: rows)
end
rm(workflow_id) click to toggle source
# File lib/gush/cli.rb, line 80
def rm(workflow_id)
  workflow = client.find_workflow(workflow_id)
  client.destroy_workflow(workflow)
end
show(workflow_id) click to toggle source
# File lib/gush/cli.rb, line 71
def show(workflow_id)
  workflow = client.find_workflow(workflow_id)

  display_overview_for(workflow) unless options[:skip_overview]

  display_jobs_list_for(workflow, options[:jobs]) unless options[:skip_jobs]
end
start(*args) click to toggle source
# File lib/gush/cli.rb, line 42
def start(*args)
  id = args.shift
  workflow = client.find_workflow(id)
  client.start_workflow(workflow, args)
end
stop(*args) click to toggle source
# File lib/gush/cli.rb, line 56
def stop(*args)
  id = args.shift
  client.stop_workflow(id)
end
viz(name) click to toggle source
# File lib/gush/cli.rb, line 115
def viz(name)
  client
  workflow = name.constantize.new
  graph = Graph.new(workflow)
  graph.viz
  Launchy.open graph.path
end
workers() click to toggle source
# File lib/gush/cli.rb, line 100
def workers
  config = client.configuration
  #puts "****** gush config cli: #{config.to_hash}"
  #cmd = " RUN sidekiq"

  #
  sidekiq_options = config.sidekiq_options || ''

  cmd = "bundle exec sidekiq -r #{config.gushfile} -c #{config.concurrency} -q #{config.sidekiq_queue} -e #{config.environment} #{sidekiq_options} -v"
  puts "#{cmd}"

  Kernel.exec cmd
end

Private Instance Methods

client() click to toggle source
# File lib/gush/cli.rb, line 125
def client
  @client ||= Client.new
end
display_jobs_list_for(workflow, jobs) click to toggle source
# File lib/gush/cli.rb, line 141
def display_jobs_list_for(workflow, jobs)
  puts overview(workflow).jobs_list(jobs)
end
display_overview_for(workflow) click to toggle source
# File lib/gush/cli.rb, line 133
def display_overview_for(workflow)
  puts overview(workflow).table
end
gushfile() click to toggle source
# File lib/gush/cli.rb, line 145
def gushfile
  Gush.configuration.gushfile
end
load_gushfile() click to toggle source
# File lib/gush/cli.rb, line 149
def load_gushfile
  file = client.configuration.gushfile
  if !gushfile.exist?
    raise Thor::Error, "#{file} not found, please add it to your project".colorize(:red)
  end

  require file
rescue LoadError
  raise Thor::Error, "failed to require #{file}".colorize(:red)
end
overview(workflow) click to toggle source
# File lib/gush/cli.rb, line 129
def overview(workflow)
  CLI::Overview.new(workflow)
end
status_for(workflow) click to toggle source
# File lib/gush/cli.rb, line 137
def status_for(workflow)
  overview(workflow).status
end