-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for halting execution plans
Up until now, Dynflow only had support for clean cancellation. Upon cancellation a cancel event was sent to all cancellable suspended and running steps and it was the action's responsibility to cancel itself. However, there were actions which just weren't cancellable at all. This commit adds support for halting execution plans. The actions are completely unaware of this, on halt dynflow just destroys its internal state about a given execution plan and turns it to stopped state. It does not remove running steps from workers as we currently don't have any real means of doing so. Any pending events will be rejected. In other words, halting an execution plan ensure it will not run any further.
- Loading branch information
1 parent
5ed8bcc
commit 475a027
Showing
10 changed files
with
123 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require_relative 'example_helper' | ||
|
||
example_description = <<DESC | ||
Halting example | ||
=================== | ||
This example shows, how halting works in Dynflow. It spawns a single action, | ||
which in turn spawns a few evented actions and a single action which occupies | ||
the executor for a long time. | ||
Once the halt event is sent, the execution plan is halted, suspended steps | ||
stay suspended forever, running steps stay running until they actually finish | ||
the current run and the execution state is flipped over to stopped state. | ||
You can see the details at #{ExampleHelper::DYNFLOW_URL} | ||
DESC | ||
|
||
class EventedCounter < Dynflow::Action | ||
def run(event = nil) | ||
output[:counter] ||= 0 | ||
output[:counter] += 1 | ||
action_logger.info "Iteration #{output[:counter]}" | ||
|
||
if output[:counter] < input[:count] | ||
plan_event(:tick, 5) | ||
suspend | ||
end | ||
action_logger.info "Done" | ||
end | ||
end | ||
|
||
class Sleeper < Dynflow::Action | ||
def run | ||
sleep input[:time] | ||
end | ||
end | ||
|
||
class Wrapper < Dynflow::Action | ||
def plan | ||
sequence do | ||
concurrence do | ||
5.times { |i| plan_action(EventedCounter, :count => i + 1) } | ||
plan_action Sleeper, :time => 20 | ||
end | ||
plan_self | ||
end | ||
end | ||
|
||
def run | ||
# Noop | ||
end | ||
end | ||
|
||
if $0 == __FILE__ | ||
puts example_description | ||
|
||
ExampleHelper.world.action_logger.level = Logger::DEBUG | ||
ExampleHelper.world | ||
t = ExampleHelper.world.trigger(Wrapper) | ||
Thread.new do | ||
sleep 8 | ||
ExampleHelper.world.halt(t.id) | ||
end | ||
|
||
ExampleHelper.run_web_console | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters