Skip to content
mosop edited this page Jan 24, 2017 · 13 revisions

An abort is an unwanted or unexpected termination of commands suspended by several reasons.

In Crystal Run, all the running processes are separated and asynchronous. So, even if some command fails, others will be continued.

If you want to stop commands running when some command fails, set the abort_on_error attribute into contexts.

cg = Run::CommandGroup.new do |g|
  g.command "wget", %w(http://essential.com), abort_on_error: true
  g.command "wget", %w(http://optional.com)
end

cg.run

In this example, if wget http://essentail.com exits with an error, the following command will never run.

In parallel processing, some processes may have been already started before other commands fail. In that case, exit signals are sent to the existing processes.

cg = Run::CommandGroup.new do |g|
  g.command "wget", %w(http://essential.com), abort_on_error: true
  g.command "wget", %w(http://optional.com)
end

cg.run parallel: true

In this example, if wget http://essential.com exits with an error, a signal is sent to the process of wget http://optional.com, only if the process is left.

Signal Number

The default signal number on aborts is Signal::TERM (15). You can specify the number with the abort_signal attribute.

cg = Run::CommandGroup.new do |g|
  g.command "wget", %w(http://essential.com), abort_on_error: true
  g.command "wget", %w(http://optional.com), abort_signal: Signal::INT
end

Aborting Globally

You can abort all processes by the Run.abort method.

Signal::INT.trap do |signal|
  Run.abort signal
end
Clone this wiki locally