Skip to content

Introduce `idempotent` worker attribute with new Cop

Oswaldo Ferreira requested to merge add-idempotency-cop-for-workers into master

What does this MR do?

It was discussed at gitlab-com/gl-infra/scalability#92 (closed) how Sidekiq encourages making workers idempotent and transactional by default.

This MR's goal is to add a cop (Scalability::IdempotentWorker) that will catch all workers that don't call idempotent! in its scope. Calling it will label the worker as idempotent, which will end up in our Sidekiq logs for further visibility.

This also introduces a shared example and a perform_multiple helper method for executing jobs multiple times through unit tests.

Also in this MR we set an example in an already idempotent worker ExpireJobCacheWorker. For this worker we call idempotent! in its scope and add tests with the new test helpers. So in summary:

  1. Introduces the idempotent! method for workers
  2. Adds a cop to catch workers that don't call it in the scope of the job class
  3. Sets ExpireJobCacheWorker as idempotent, adding tests with introduced helper methods / shared example

Docs !25551 (merged)

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Edited by Oswaldo Ferreira

Merge request reports