Skip to content

Fix WorkerDataConsistency cop offenses [RUN AS-IF-FOSS]

What does this MR do?

Fixes all cop offenses silenced in !65341 (merged) and removes the silence.

Semantically this is a no-op; setting data_consistency to :always had been the default previously. We are merely making this explicit in code, so as to encourage teams to always consider this setting during development, rather than it being tucked away in a yaml file.

This is somewhat different to a merely syntactical offense because domain knowledge is required to decide for each worker whether it is safe to use replicas or not, and it is not feasible for our team to make these decisions on behalf of others. Only for newly added workers we now enforce this decision to be made consciously.

More about worker data consistency here: https://docs.gitlab.com/ee/development/sidekiq_style_guide.html#job-data-consistency-strategies

I tried to catch all existing offenses by running the cop, then using a script to insert data_consistency :always, which is semantically a no-op (as it's the default).

bin/bundle exec rubocop --parallel app/workers ee/app/workers | egrep -o '(ee/)?app/workers/[^:]+' | ./fix-cop-offenses.rb

script:

#!/usr/bin/env ruby
$stdin.each_line do |worker|
  path = worker.strip
  puts "Processing #{path}"
  contents = IO.read(File.join(Dir.pwd, path))

  new_contents =
    contents.gsub(/^( +)include ApplicationWorker$/,
                  "\\1include ApplicationWorker\n\n" +
                  "\\1data_consistency :always")
  IO.write(path, new_contents)
end

based on Sean's work in ab0f9788

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Closes #335170 (closed)

Edited by Matthias Käppler

Merge request reports