Fix future iterations not being scheduled
What does this MR do and why?
Resolves #365741 (closed).
An iterations cadence, cadence for short, contains many iterations (one-to-many.) Iterations for a cadence are scheduled and created automatically without user intervention by workers like this:
-
Iterations::Cadences::ScheduleCreateIterationsWorker
batches through cadences. The worker picks up cadences using the scopeIterations::Cadence.for_automated_iterations
-
For each cadence,
Iterations::Cadences::CreateIterationsWorker
is executed.
Unfortunately, the scope :for_automated_iterations
is incorrect and iterations are not being correctly created. In this MR, we are
-
fixing the scope
-
and running a data migration so that
Iterations::Cadences::ScheduleCreateIterationsWorker
can pick up all the cadences whose iterations have not been scheduled correctly.
How to set up and validate locally
The attribute last_run_date
cannot be manually set and the validation steps are somewhat more involved.
-
Ensure that
:iterations_cadences
is enabled (the FF is enabled by default.)Feature.enable(:iterations_cadences)
-
Temporarily comment out the following line so that the worker isn't run when a new cadence record is created:
Comment out ee/app/models/iterations/cadence.rb#77
def ensure_iterations_in_advance
- ::Iterations::Cadences::CreateIterationsWorker.perform_async(self.id) if self.can_be_automated?
+ # ::Iterations::Cadences::CreateIterationsWorker.perform_async(self.id) if self.can_be_automated?
end
- Create a new cadence whose
last_run_date
is in the past.
This cadence should be picked up by 'ScheduleCreateIterationsWorker' because it uses the updated scope Iterations::Cadence.next_to_auto_schedule
.
The cadence wouldn't have been picked up with the old scope Iterations::Cadence.for_automated_iterations
.
common_args = {
group: Group.last, # Use your preferred group
start_date: Date.today,
title: "Sample Cadence",
duration_in_weeks: 1,
iterations_in_advance: 2,
}
cadence_a = Iterations::Cadence.create(**common_args, last_run_date: Date.today - 5.days)
- Create a new cadence whose
last_run_date
is in the future.
cadence_b = Iterations::Cadence.create(**common_args, last_run_date: Date.today + 5.days)
- Run the worker
Iterations::Cadences::ScheduleCreateIterationsWorker
in the rails console (this may take some minutes. Please check the application log.)
Iterations::Cadences::ScheduleCreateIterationsWorker.perform_in(1.second)
- Verify that only
cadence_a
has iteration records associated.
cadence_a.reload.iterations.size # expected 2
cadence_b.reload.iterations.size # expected 0
Database Review
The query plan for the post migration: !90620 (comment 998516410).
The post migration is a data migration and would update ~1k records in production (~100 in staging)
Query plan (cold cache/dblab):
gitlabhq_dblab=# explain (analyze, buffers) UPDATE iterations_cadences SET last_run_date=CURRENT_DATE WHERE automatic=true;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------
Update on iterations_cadences (cost=0.00..336.77 rows=989 width=88) (actual time=260.461..260.462 rows=0 loops=1)
Buffers: shared hit=10042 read=177 dirtied=184 written=17
I/O Timings: read=208.046
-> Seq Scan on iterations_cadences (cost=0.00..336.77 rows=989 width=88) (actual time=2.626..78.901 rows=998 loops=1)
Filter: automatic
Rows Removed by Filter: 3636
Buffers: shared hit=33 read=39 dirtied=8
I/O Timings: read=61.299
Planning Time: 46.058 ms
Execution Time: 261.324 ms
(10 rows)
The query plan for the modified scope Iterations:Cadence.next_to_auto_schedule
: !90620 (comment 998538261)
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.