Skip to content

Instantly share code, notes, and snippets.

@adamruzicka
Created March 20, 2024 14:39
Show Gist options
  • Save adamruzicka/55694a152421166de22cf34585265b8c to your computer and use it in GitHub Desktop.
Save adamruzicka/55694a152421166de22cf34585265b8c to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Place this into ${dynflow_checkout}/examples/cancellation.rb
# run with ruby examples/cancellation.rb
# frozen_string_literal: true
require_relative 'example_helper'
class SequentialParent < Dynflow::Action
def plan(klass, count = 10, args: [])
2.times do
concurrence do
sequence do
count.times do
plan_action klass
end
end
end
end
end
end
class Sleeper < Dynflow::Action
include ::Dynflow::Action::Cancellable
def plan(interval = 60)
plan_self interval: interval
end
def run(event = nil)
case event
when nil
plan_event(:wake, input[:interval])
suspend
when :wake
when Dynflow::Action::Skip
else
super
end
end
def rescue_strategy
::Dynflow::Action::Rescue::Fail
end
end
if $0 == __FILE__
world = ExampleHelper.create_world do |config|
config.auto_rescue = true
end
world.action_logger.level = 1
world.logger.level = 0
world.trigger(SequentialParent, Sleeper)
ExampleHelper.run_web_console(world)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment