Skip to content

Unify the logic of retrying

The following discussion from !54300 (merged) should be addressed:

  • @fabiopitino started a discussion: (+2 comments)

    I think the change is ok overall. I'm thinking whether we could take this opportunity to enforce the following invariant: "when a job is added to an existing pipeline we need to ensure previous jobs are marked as retried".

    An idea would be to have a method like below that represents the SSOT for adding new jobs to existing pipeline

    class Ci::Pipeline
      # Use this method to add a job to an existing pipeline
      def add_job!(job)
        raise "Pipeline must be persisted for this method to be used" unless persisted?
    
        # these also ensures other invariants such as
        # a job takes project and ref from the pipeline it belongs to
        job.pipeline = self
        job.project = self.project
        job.ref = self.ref
    
        self.class.transaction do
          job.save!
          job.update_older_statuses_retried!
        end
    
        job
      end
    end

    Then this service could use it as:

    pipeline = build.pipeline
    @status = pipeline.add_job!(GenericCommitStatus.new(
      user: current_user,
      stage: 'deploy',
      name: 'pages:deploy'))

    EDIT: with the guard clause we could also ensure that the job being added is not persisted either.

  • !54300 (comment 514109156)

    Ci::RetryBuildService uses the same logic. Should we find a way to remove this duplication?

Availability & Testing

Edited by Furkan Ayhan