Class: Tap::Controllers::App
- Inherits:
-
Tap::Controller
- Object
- Tap::Controller
- Tap::Controllers::App
- Defined in:
- lib/tap/controllers/app.rb
Overview
:startdoc::controller builds and runs workflows
Constant Summary
Constants inherited from Tap::Controller
Instance Attribute Summary
Attributes inherited from Tap::Controller
#controller_path, #request, #response, #server
Instance Method Summary collapse
- #build ⇒ Object
- #enque ⇒ Object
-
#info ⇒ Object
Returns the controls and current application info.
- #reset ⇒ Object
-
#run ⇒ Object
Runs app on a separate thread (on post).
-
#state ⇒ Object
Returns the state of app.
-
#stop ⇒ Object
Stops app (on post).
- #tail(id) ⇒ Object
-
#terminate ⇒ Object
Teminates app (on post).
Methods inherited from Tap::Controller
#action?, call, #call, #dispatch, get, inherited, #initialize, #module_path, #module_render, nest, #redirect, #render, #render_erb, #render_layout, #route, set, set_variables, #template_path, #uri
Constructor Details
This class inherits a constructor from Tap::Controller
Instance Method Details
#build ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/tap/controllers/app.rb', line 56 def build schema = request[:schema] || server.data.read(:schema, request[:id]) unless request.post? return render('build.erb', :schema => schema, :layout => true) end schema = Tap::Schema.load(schema).resolve! do |type, key, data| server.env.manifest(type)[key] end.validate! if request[:reset] == "on" app.reset end tasks.merge!(server.env.build(schema, app)) if request[:run] == "on" run else redirect uri(:enque) end end |
#enque ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/tap/controllers/app.rb', line 80 def enque unless request.post? return render('enque.erb', :layout => true) end queue = if request[:load] YAML.load(request[:queue] || "{}") else request[:queue] || {} end queue.each do |(key, inputs)| unless task = tasks[key] raise "no task for: #{key}" end app.enq(task, *inputs) end redirect uri(:info) end |
#info ⇒ Object
Returns the controls and current application info.
24 25 26 27 28 |
# File 'lib/tap/controllers/app.rb', line 24 def info render 'info.erb', :locals => { :actions => [:run, :stop, :terminate, :reset], }, :layout => true end |
#reset ⇒ Object
39 40 41 42 |
# File 'lib/tap/controllers/app.rb', line 39 def reset app.reset if request.post? redirect uri(:info) end |
#run ⇒ Object
Runs app on a separate thread (on post).
31 32 33 34 35 36 37 |
# File 'lib/tap/controllers/app.rb', line 31 def run if request.post? server.thread ||= Thread.new { app.run; server.thread = nil; } end redirect uri(:info) end |
#state ⇒ Object
Returns the state of app.
19 20 21 |
# File 'lib/tap/controllers/app.rb', line 19 def state app.state.to_s end |
#stop ⇒ Object
Stops app (on post).
45 46 47 48 |
# File 'lib/tap/controllers/app.rb', line 45 def stop app.stop if request.post? redirect uri(:info) end |
#tail(id) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/tap/controllers/app.rb', line 101 def tail(id) unless data.has?("#{id}.log") raise Tap::ServerError.new("invalid id: #{id}", 404) end path = data.path("#{id}.log") pos = request['pos'].to_i if pos > File.size(path) raise Tap::ServerError.new("tail position out of range (try update)", 500) end content = File.open(path) do |file| file.pos = pos file.read end if request.post? content else render('tail.erb', :locals => { :id => id, :path => File.basename(path), :update => true, :content => content }, :layout => true) end end |
#terminate ⇒ Object
Teminates app (on post).
51 52 53 54 |
# File 'lib/tap/controllers/app.rb', line 51 def terminate app.terminate if request.post? redirect uri(:info) end |