class Console::Event::Spawn
“‘
event.status = Process.wait
event = Console::Event::Spawn.for(“ls”, “-l”)
Console.info(self, **Console::Event::Spawn.for(“ls”, “-l”))
“`ruby
Represents a child process spawn event.
def self.for(*arguments, **options)
@parameter options [Hash] The options to pass to the command, similar to how you would pass them to `Kernel.system` or `Process.spawn`.
@parameter arguments [Array] The arguments to the command, similar to how you would pass them to `Kernel.system` or `Process.spawn`.
Create a new spawn event.
def self.for(*arguments, **options) # Extract out the command environment: if arguments.first.is_a?(Hash) environment = arguments.shift self.new(environment, arguments, options) else self.new(nil, arguments, options) end end
def duration
Calculate the duration of the command, if it has completed.
def duration if @end_time @end_time - @start_time end end
def emit(*arguments, **options)
@parameter arguments [Array] The arguments to log.
Log the spawn event.
def emit(*arguments, **options) options[:severity] ||= :info super end
def initialize(environment, arguments, options)
@parameter arguments [Array] The arguments used for command execution.
@parameter environment [Hash] The environment to use when running the command.
Create a new spawn event.
def initialize(environment, arguments, options) @environment = environment @arguments = arguments @options = options @start_time = Clock.now @end_time = nil @status = nil end
def status=(status)
Set the status of the command, and record the end time.
def status=(status) @end_time = Time.now @status = status end
def to_hash
Convert the spawn event to a hash suitable for JSON serialization.
def to_hash Hash.new.tap do |hash| hash[:type] = :spawn hash[:environment] = @environment if @environment&.any? hash[:arguments] = @arguments if @arguments&.any? hash[:options] = @options if @options&.any? hash[:status] = @status.to_i if @status if duration = self.duration hash[:duration] = duration end end end