Add the rules for auto-cancelling a redundant pipeline
What does this MR do and why?
This MR adds Gitlab::Ci::RedundantPipelines::AutoCancelPolicy. The four callers arrive in later merge requests, so nothing calls this class today.
graph LR
A["StartPipelineService"] -->|"cancelable_by_newer_pipeline?"| P["AutoCancelPolicy<br/>(this MR)"]
B["CancelRedundantPipelinesWorker"] -->|"applies?"| P
C["Ci::Build starts a job"] -->|"protected_after_non_interruptible_job_starts?"| P
D["PipelineFamily"] -->|"cancel_mode"| P
P --> E["pipeline metadata,<br/>processing data,<br/>feature flags"]The class answers four questions about one pipeline. applies? tells you auto-cancel applies to this pipeline on its own. A child pipeline never qualifies, because it can only be cancelled with its parent. cancelable_by_newer_pipeline? tells you a newer pipeline may cancel this one. cancel_mode returns :all, :interruptible, or nil. protected_after_non_interruptible_job_starts? tells you that starting a job that cannot be interrupted puts the pipeline out of reach for good. The MR also adds Ci::Pipeline#interruptible_protected?, which reads the existing p_ci_pipeline_processing_data.interruptible_protected column. The work sits behind the feature flag ci_redundant_pipeline_candidates_cache, type wip, default disabled.
Ci::PipelineCreation::CancelRedundantPipelinesService finds pipelines to cancel by querying the partitioned tables p_ci_pipelines and p_ci_builds on a hot path. This class gathers the rules in one place, so a later MR can answer them without those queries. This is one small piece split out of a proof-of-concept MR.
How to set up and validate locally
bundle exec rspec spec/lib/gitlab/ci/redundant_pipelines/auto_cancel_policy_spec.rbThe suite runs 27 examples and all pass. Nothing else needs validation, because no caller exists.
References
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.