Created
July 2, 2024 14:59
-
-
Save mokevnin/e21c56f32ee5a8660ee60a2410491598 to your computer and use it in GitHub Desktop.
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
state_machine initial: :not_pulled do | |
state :not_pulled | |
state :pulling | |
state :pulled | |
state :code_copying | |
state :code_copied | |
state :creating | |
state :created | |
state :starting | |
state :started | |
state :stopping | |
state :stopped | |
state :failed | |
state :outdated | |
event :outdate do | |
transition all => :outdated | |
end | |
event :pull do | |
transition %i[not_pulled pulling | |
code_copying code_copied | |
creating created | |
starting started | |
stopping stopped] => :pulling, | |
if: ->(r) { r.server_status.alive? } | |
end | |
event :mark_as_pulled do | |
transition pulling: :pulled | |
end | |
event :copy_code do | |
transition %i[pulled code_copying] => :code_copying | |
end | |
event :mark_as_code_copied do | |
transition code_copying: :code_copied | |
end | |
event :create_container do | |
transition %i[stopped created starting started code_copied creating] => :creating | |
end | |
event :mark_as_created do | |
transition creating: :created | |
end | |
event :start do | |
transition %i[stopped created starting started] => :starting | |
end | |
event :mark_as_started do | |
transition starting: :started | |
end | |
event :stop do | |
transition %i[started stopping] => :stopping | |
end | |
event :mark_as_stopped do | |
transition %i[stopping stopped] => :stopped | |
end | |
event :mark_as_failed do | |
transition all => :failed | |
end | |
before_transition from: all - :stopping, to: :stopping, do: :set_last_attempt_to_stop | |
before_transition to: :started, do: :set_started_at | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment