Class: Rundoc::CodeCommand::Background::Start

Inherits:
Rundoc::CodeCommand show all
Defined in:
lib/rundoc/code_command/background/start.rb

Constant Summary

Constants inherited from Rundoc::CodeCommand

NEWLINE

Instance Attribute Summary

Attributes inherited from Rundoc::CodeCommand

#command, #contents, #keyword, #original_args, #render_command, #render_result

Instance Method Summary collapse

Methods inherited from Rundoc::CodeCommand

#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
17
18
19
20
# 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)
  @command = command
  @name = name
  @wait = wait
  @allow_fail = allow_fail
  FileUtils.touch(log)

  @spawn = ProcessSpawn.new(
    @command,
    timeout: timeout,
    log: log,
    out: out
  )
  puts "Spawning commmand: `#{@spawn.command}`"
  ProcessSpawn.add(@name, @spawn)
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/rundoc/code_command/background/start.rb', line 33

def alive?
  !!@spawn.alive?
end

#call(env = {}) ⇒ Object



26
27
28
29
30
31
# File 'lib/rundoc/code_command/background/start.rb', line 26

def call(env = {})
  @spawn.wait(@wait)
  @spawn.check_alive! unless @allow_fail

  @spawn.log.read
end

#to_md(env = {}) ⇒ Object



22
23
24
# File 'lib/rundoc/code_command/background/start.rb', line 22

def to_md(env = {})
  "$ #{@command}"
end