Class: Gush::CLI
- Inherits:
-
Thor
- Object
- Thor
- Gush::CLI
- Defined in:
- lib/gush/cli.rb,
lib/gush/cli/overview.rb
Defined Under Namespace
Classes: Overview
Instance Method Summary collapse
- #create(name) ⇒ Object
- #create_and_start(name, *args) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #list ⇒ Object
- #rm(workflow_id) ⇒ Object
- #show(workflow_id) ⇒ Object
- #start(*args) ⇒ Object
- #stop(*args) ⇒ Object
- #viz(class_or_id) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gush/cli.rb', line 14 def initialize(*) super Gush.configure do |config| config.gushfile = .fetch("gushfile", config.gushfile) config.concurrency = .fetch("concurrency", config.concurrency) config.redis_url = .fetch("redis", config.redis_url) config.namespace = .fetch("namespace", config.namespace) config.ttl = .fetch("ttl", config.ttl) config.locking_duration = .fetch("locking_duration", config.locking_duration) config.polling_interval = .fetch("polling_interval", config.polling_interval) end load_gushfile end |
Instance Method Details
#create(name) ⇒ Object
29 30 31 32 33 |
# File 'lib/gush/cli.rb', line 29 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) ⇒ Object
43 44 45 46 47 |
# File 'lib/gush/cli.rb', line 43 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 ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/gush/cli.rb', line 74 def list workflows = client.all_workflows rows = workflows.map do |workflow| [workflow.id, (Time.at(workflow.started_at) if workflow.started_at), workflow.class, {alignment: :center, value: status_for(workflow)}] end headers = [ {alignment: :center, value: 'id'}, {alignment: :center, value: 'started at'}, {alignment: :center, value: 'name'}, {alignment: :center, value: 'status'} ] puts Terminal::Table.new(headings: headers, rows: rows) end |
#rm(workflow_id) ⇒ Object
68 69 70 71 |
# File 'lib/gush/cli.rb', line 68 def rm(workflow_id) workflow = client.find_workflow(workflow_id) client.destroy_workflow(workflow) end |
#show(workflow_id) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/gush/cli.rb', line 59 def show(workflow_id) workflow = client.find_workflow(workflow_id) display_overview_for(workflow) unless [:skip_overview] display_jobs_list_for(workflow, [:jobs]) unless [:skip_jobs] end |
#start(*args) ⇒ Object
36 37 38 39 40 |
# File 'lib/gush/cli.rb', line 36 def start(*args) id = args.shift workflow = client.find_workflow(id) client.start_workflow(workflow, args) end |
#stop(*args) ⇒ Object
50 51 52 53 |
# File 'lib/gush/cli.rb', line 50 def stop(*args) id = args.shift client.stop_workflow(id) end |
#viz(class_or_id) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/gush/cli.rb', line 91 def viz(class_or_id) client begin workflow = client.find_workflow(class_or_id) rescue WorkflowNotFound workflow = nil end unless workflow begin workflow = class_or_id.constantize.new rescue NameError => e STDERR.puts Paint["'#{class_or_id}' is not a valid workflow class or id", :red] exit 1 end end opts = {} if [:filename] opts[:filename], opts[:path] = File.split([:filename]) end graph = Graph.new(workflow, **opts) graph.viz if ([:open].nil? && ![:filename]) || [:open] Launchy.open Pathname.new(graph.path).realpath.to_s end end |