Skip to content

Ensure pipeline schedule is triggered only once

What does this MR do and why?

Currently, since PipelineScheduleWorker is run every 5 minutes, and sometimes it lasts for more than 5 minutes, and when this happens, multiple RunPipelineScheduleWorkers will be enqueued and executed. This fix is based on the existing deduplication strategy :until_executed to prevent multiple RunPipelineScheduleWorkers with same pipeline schedule ID and user ID from being executed.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

  1. First create a project 338609-test-pipeline-schedule with following CI configuration for .gitlab-ci.yml:
image: busybox:latest

build:
  script:
    - echo "Do your build here"
    - sleep 30
  1. Add a sleep to PipelineScheduleWorker after line 16:
      next unless schedule.project

      sleep 2 # here
  1. Create a pipeline schedule and look up the schedule in Rails console, then update the next_run_at to 1.hour.ago:
ps = Ci::PipelineSchedule.last
ps.update_column(:next_run_at, 1.hour.ago)
  1. Run PipelineScheduleWorker for 2 times in Rails console:
2.times { PipelineScheduleWorker.perform_async }
  1. Check and see how many pipeline schedules have been executed

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #338609 (closed)

Edited by Tianwen Chen

Merge request reports