Container Repository state machine for migration_state
🗺 Context
We are preparing for Phase 2 of the Container Registry migration which involves importing all existing container repositories to the new platform (Phase 1 involved routing all new container repositories to the new platform). See &7316 (closed) for full details of how the import will work.
As we import container repositories, we need a way to track what state they are in and perform actions when moving from one state to the next.
💡 What does this MR do and why?
We introduce a state machine to the ContainerRepository
model on the migration_state
column. This state machine defines the various states a container repository can be in while importing:
default
pre_importing
pre_import_done
importing
import_done
import_aborted
import_skipped
Depending on which state is transitioning we have a few callbacks to update timestamps and columns to help with any potential problems.
There are a few commented out steps that are waiting on other issues being worked on in parallel to this issue. They will be added very quickly after this is merged (all within %14.8).
🎞 Screenshots or screen recordings
[6] pry(main)> c = ContainerRepository.create(project: Project.first, name: '')
=> #<ContainerRepository:0x00007fc543b169c0
id: 1,
project_id: 1,
name: "",
created_at: Tue, 18 Jan 2022 22:11:20.096654000 UTC +00:00,
updated_at: Tue, 18 Jan 2022 22:11:20.096654000 UTC +00:00,
status: nil,
expiration_policy_started_at: nil,
expiration_policy_cleanup_status: "cleanup_unscheduled",
expiration_policy_completed_at: nil,
migration_pre_import_started_at: nil,
migration_pre_import_done_at: nil,
migration_import_started_at: nil,
migration_import_done_at: nil,
migration_skipped_at: nil,
migration_retries_count: 0,
migration_skipped_reason: nil,
migration_state: "default",
migration_aborted_in_state: nil>
[7] pry(main)> c.migration_state
=> "default"
[9] pry(main)> c.start_pre_import
=> true
[10] pry(main)> c.migration_pre_import_started_at
=> Tue, 18 Jan 2022 22:11:57.878455000 UTC +00:00
[11] pry(main)> c.finish_pre_import
=> true
[12] pry(main)> c.migration_pre_import_done_at
=> Tue, 18 Jan 2022 22:12:13.255888000 UTC +00:00
[13] pry(main)> c.start_import
=> true
[14] pry(main)> c.migration_import_started_at
=> Tue, 18 Jan 2022 22:13:29.929141000 UTC +00:00
[15] pry(main)> c.abort_import
=> true
[16] pry(main)> c.migration_aborted_in_state
=> "importing"
[22] pry(main)> c.retry_import
=> true
[23] pry(main)> c.migration_retries_count
=> 1
[24] pry(main)> c.skip_import
=> true
[25] pry(main)> c.migration_skipped_at
=> Tue, 18 Jan 2022 22:14:18.938272000 UTC +00:00
[26] pry(main)> c.migration_skipped_reason
=> "not_specified"
💻 How to set up and validate locally
In a rails console, create a ContainerRepository
locally and try changing the migration_state
. You can use the screenshots section above for an example of how to create the object and what the output might look like.
✏ MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #350591 (closed)