Class: Rundoc::CodeCommand::Background::Start
Constant Summary
NEWLINE, RUNDOC_DEFAULT_ERB_BINDING, RUNDOC_ERB_BINDINGS
Instance Attribute Summary
#command, #contents, #keyword, #original_args, #render_command, #render_result
Instance Method Summary
collapse
#hidden?, #not_hidden?, #push
Constructor Details
#initialize(command, name:, wait: nil, timeout: 5, log: Tempfile.new("log"), out: "2>&1", allow_fail: false) ⇒ Start
Returns a new instance of Start.
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/rundoc/code_command/background/start.rb', line 5
def initialize(command, name:, wait: nil, timeout: 5, log: Tempfile.new("log"), out: "2>&1", allow_fail: false)
@timeout = timeout
@command = command
@name = name
@wait = wait
@allow_fail = allow_fail
@log = log
@redirect = out
FileUtils.touch(@log)
@background = nil
end
|
Instance Method Details
#alive? ⇒ Boolean
41
42
43
|
# File 'lib/rundoc/code_command/background/start.rb', line 41
def alive?
!!background.alive?
end
|
#background ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/rundoc/code_command/background/start.rb', line 18
def background
@background ||= ProcessSpawn.new(
@command,
timeout: @timeout,
log: @log,
out: @redirect
).tap do |spawn|
puts "Spawning commmand: `#{spawn.command}`"
ProcessSpawn.add(@name, spawn)
end
end
|
#call(env = {}) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/rundoc/code_command/background/start.rb', line 34
def call(env = {})
background.wait(@wait)
background.check_alive! unless @allow_fail
background.log.read
end
|
#to_md(env = {}) ⇒ Object
30
31
32
|
# File 'lib/rundoc/code_command/background/start.rb', line 30
def to_md(env = {})
"$ #{@command}"
end
|