Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample actions for tasks development #392

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions app/lib/actions/try.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
unless Rails.env.production?
module Actions
module Try
# A set of actions to try different scenarios with tasks in development.
#
# Usage:
# from rails console, run:
#
# # Successful task (ending in stopped state/success result)
# ForemanTasks.sync_task(Actions::Try::Success)
#
# # Failing task task (ending in paused state/error result)
# ForemanTasks.sync_task(Actions::Try::Pause)
#
# # Task that fails but resumes (ending in stopped state/warning result)
# ForemanTasks.sync_task(Actions::Try::Skip)
class Success < Actions::EntryAction
def plan
plan_self(hello: 'world')
end

def run
end
end

class Pause < Actions::EntryAction
def plan
plan_self(hello: 'world')
end

def run
error! "This is an error"
end
end

class Skip < Actions::EntryAction
def plan
plan_self(hello: 'world')
end

def run
error! "This is an error, but will be skipped"
end

def rescue_strategy
::Dynflow::Action::Rescue::Skip
end
end
end
end
end