Class: Do::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/do/executor.rb

Overview

Executes a task's command as an argument list, without a shell.

The command string is split into argv tokens lexically (respecting quoting but performing no variable expansion, ~ expansion, or globbing). This is the safe, declarative default described in the spec. Tasks that genuinely need shell features must request them explicitly, e.g. by prefixing with bash -lc '...'.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(systemd: Systemd.new) ⇒ Executor

Returns a new instance of Executor.



15
16
17
# File 'lib/do/executor.rb', line 15

def initialize(systemd: Systemd.new)
  @systemd = systemd
end

Instance Attribute Details

#systemdObject (readonly)

Returns the value of attribute systemd.



13
14
15
# File 'lib/do/executor.rb', line 13

def systemd
  @systemd
end

Instance Method Details

#run(task) ⇒ Integer

Run the task immediately and return its exit status. The timer schedule is never altered by manual execution.

Returns:

  • (Integer)

    process exit status

Raises:



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/do/executor.rb', line 23

def run(task)
  argv = Shellwords.split(task.command)
  raise Error, "task '#{task.name}' has an empty command" if argv.empty?

  env_overrides = task.environment || {}
  options = {}
  options[:chdir] = File.expand_path(task.working_directory) if task.working_directory

  pid = Process.spawn(env_overrides, *argv, options)
  _pid, status = Process.wait2(pid)
  status.exitstatus || 0
end