-
Notifications
You must be signed in to change notification settings - Fork 1
Callbacks and Events
mosop edited this page Jan 4, 2017
·
24 revisions
Note: This feature is not supported from 0.5.
You can set callbacks to command groups. A callback is a Proc object and called when the corresponding event is occurred.
class WhatsWrong < Run::CommandGroup
on_group_abort do |cg, pg|
puts "what's wrong?"
end
on_abort do |cg, p|
puts "what's wrong, #{p.context.command}?"
end
end
cg = WhatsWrong.new
cg.command "/bin/bash", ["-c", "exit 2"], abort_on_error: true
cg.command "sleep", ["100"]
cg.run.wait
This prints:
what's wrong?
what's wrong, sleep?
You must inherit Run::CommandGroup and use the inheriting class for setting callbacks because callbacks are set to the class variables.
Occurs when a single process are killed or timed out on abort.
Occurs when all the descendant processes in a process group are killed or timed out on abort.