Skip to content

Update BBM Best practices Docs

What does this MR do and why?

Describe in detail what your merge request does and why.

Solves:

  • Update our BBM docs best practices section: Include some information about job classes not to rescue exceptions that happen during the job/batch execution.

Update docs best practices to:

Best practices

  1. Know how much data you're dealing with.
  2. Make sure the batched background migration jobs are idempotent.
  3. Confirm the tests you write are not false positives.
  4. If the data being migrated is critical and cannot be lost, the clean-up migration must also check the final state of the data before completing.
  5. Discuss the numbers with a database specialist. The migration may add more pressure on DB than you expect. Measure on staging, or ask someone to measure on production.
  6. Know how much time is required to run the batched background migration.
  7. Do not silently rescue exceptions inside job classes.
# good
def perform
  each_sub_batch do |sub_batch|
    sub_batch.update_all(name: 'My Name')
  end
end

# acceptable
def perform
  each_sub_batch do |sub_batch|
    sub_batch.update_all(name: 'My Name')
  rescue Exception => error
    logger.error(message: error.message, class: self.class.name)

    raise
  end
end

# bad
def perform
  each_sub_batch do |sub_batch|
    sub_batch.update_all(name: 'My Name')
  rescue Exception => error
    logger.error(message: error.message, class: self.class.name)
  end
end

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 #403073 (closed)

Edited by Leonardo da Rosa

Merge request reports