Validate job arguments when scheduling batched migrations
What does this MR do and why?
When scheduling batched migration, make sure the number of job arguments provided match the number of job arguments defined in the migration's job class.
This effectively will enforce the use of the job_arguments
DSL for batched migration jobs introduced with !93438 (merged).
Related to #357900 (closed).
How to set up and validate locally
- Create a new batch migration job:
# frozen_string_literal: true # lib/gitlab/background_migration/test_job_arguments_validation.rb module Gitlab module BackgroundMigration class TestJobArgumentsValidation < BatchedMigrationJob def perform end end end end
- Try to schedule the migration with
queue_batched_background_migration( 'TestJobArgumentsValidation', :projects, :id, 'name', 'name_convert_to_text', job_interval: 2.minutes )
- This will fail with error like
$ bundle exec rails db:migrate:up:main VERSION=20220729015320 main: == 20220729015320 TestJobArgumentsValidation: migrating ======================= rails aborted! StandardError: An error has occurred, all later migrations canceled: wrong number of job arguments for TestJobArgumentsValidation (given 2, expected 0)
- Update
lib/gitlab/background_migration/test_job_arguments_validation.rb
to# frozen_string_literal: true # lib/gitlab/background_migration/test_job_arguments_validation.rb module Gitlab module BackgroundMigration class TestJobArgumentsValidation < BatchedMigrationJob job_arguments :copy_from, :copy_to def perform end end end end
- Scheduling the migration will now suceed
$ bundle exec rails db:migrate:up:main VERSION=20220729015320 main: == 20220729015320 TestJobArgumentsValidation: migrating ======================= main: == 20220729015320 TestJobArgumentsValidation: migrated (0.0277s) ==============
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.
Edited by Krasimir Angelov