Introduce the `finalized` status
Context:
This issue aims to add a new status and a new transition to the batched background migrations state machine.
We decided to add this additional status to track which batched background migrations are finalized. In the future, using this information will ship new features like updating the merge request labels when a batched background migration is finalized and removing batched background migrations that are finalized from the system.
The current status and transitions:
state_machine :status, initial: :paused do
state :paused, value: 0
state :active, value: 1
state :finished, value: 3
state :failed, value: 4
state :finalizing, value: 5
event :pause do
transition [:active, :paused] => :paused
end
event :execute do
transition [:active, :paused, :failed] => :active
end
event :finish do
transition [:paused, :finished, :active, :finalizing] => :finished
end
event :failure do
transition [:failed, :finalizing, :active] => :failed
end
event :finalize do
transition any => :finalizing
end
before_transition any => :finished do |migration|
migration.finished_at = Time.current if migration.respond_to?(:finished_at)
end
before_transition any => :active do |migration|
migration.started_at = Time.current if migration.respond_to?(:started_at)
end
end
Goal:
-
Add the finalized
status to the state machine -
Update the olds records -
Update the ensure_batched_background_migration_is_finished
helper
Edited by Leonardo da Rosa