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
# 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
  )
  ProcessSpawn.add(@name, @spawn)
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


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

def alive?
  !!@spawn.alive?
end

#call(env = {}) ⇒ Object



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

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

  @spawn.log.read
end

#to_md(env = {}) ⇒ Object



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

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