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 RunPipelineScheduleWorker
s will be enqueued and executed. This fix is based on the existing deduplication strategy :until_executed
to prevent multiple
RunPipelineScheduleWorker
s 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
- 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
- Add a
sleep
toPipelineScheduleWorker
after line 16:
next unless schedule.project
sleep 2 # here
- 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)
- Run
PipelineScheduleWorker
for 2 times in Rails console:
2.times { PipelineScheduleWorker.perform_async }
- 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.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #338609 (closed)
Edited by Tianwen Chen