Class: Gush::CLI
- Inherits:
-
Thor
- Object
- Thor
- Gush::CLI
- Defined in:
- lib/gush/cli.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #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(name) ⇒ Object
- #workers ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gush/cli.rb', line 16 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.environment = .fetch("environment", config.environment) end end |
Instance Method Details
#clear ⇒ Object
66 67 68 |
# File 'lib/gush/cli.rb', line 66 def clear Sidekiq::Queue.new(client.configuration.namespace).clear end |
#create(name) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/gush/cli.rb', line 28 def create(name) workflow = client.create_workflow(name) puts "Workflow created with id: #{workflow.id}" puts "Start it with command: gush start #{workflow.id}" rescue puts "Workflow not found." end |
#create_and_start(name, *args) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/gush/cli.rb', line 47 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}" rescue WorkflowNotFound puts "Workflow not found." rescue DependencyLevelTooDeep puts "Dependency level too deep. Perhaps you have a dependency cycle?" end |
#list ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/gush/cli.rb', line 93 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) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/gush/cli.rb', line 85 def rm(workflow_id) workflow = client.find_workflow(workflow_id) client.destroy_workflow(workflow) rescue WorkflowNotFound puts "Workflow not found." end |
#show(workflow_id) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/gush/cli.rb', line 74 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] rescue WorkflowNotFound puts "Workflow not found." end |
#start(*args) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/gush/cli.rb', line 37 def start(*args) id = args.shift client.start_workflow(id, args) rescue WorkflowNotFound puts "Workflow not found." rescue DependencyLevelTooDeep puts "Dependency level too deep. Perhaps you have a dependency cycle?" end |
#stop(*args) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/gush/cli.rb', line 58 def stop(*args) id = args.shift client.stop_workflow(id) rescue WorkflowNotFound puts "Workflow not found." end |
#viz(name) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/gush/cli.rb', line 113 def viz(name) client workflow = name.constantize.new("start") GraphViz.new(:G, type: :digraph, dpi: 200, compound: true) do |g| g[:compound] = true g[:rankdir] = "LR" g[:center] = true g.node[:shape] = "ellipse" g.node[:style] = "filled" g.node[:color] = "#555555" g.node[:fillcolor] = "white" g.edge[:dir] = "forward" g.edge[:penwidth] = 1 g.edge[:color] = "#555555" start = g.start(shape: 'diamond', fillcolor: '#CFF09E') end_node = g.end(shape: 'diamond', fillcolor: '#F56991') workflow.nodes.each do |job| name = job.class.to_s g.add_nodes(name) if job.incoming.empty? g.add_edges(start, name) end if job.outgoing.empty? g.add_edges(name, end_node) else job.outgoing.each do |out| g.add_edges(name, out) end end end g.output(png: Pathname.new(Dir.tmpdir).join("graph.png")) end Launchy.open(Pathname.new(Dir.tmpdir).join("graph.png").to_s) end |
#workers ⇒ Object
107 108 109 110 |
# File 'lib/gush/cli.rb', line 107 def workers config = client.configuration Kernel.exec "bundle exec sidekiq -r #{config.gushfile} -c #{config.concurrency} -q #{config.namespace} -e #{config.environment} -v" end |