Introduce `idempotent` worker attribute with new Cop
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:
- Introduces the
idempotent!
method for workers - Adds a cop to catch workers that don't call it in the scope of the job class
- Sets
ExpireJobCacheWorker
as idempotent, adding tests with introduced helper methods / shared example
Docs !25551 (merged)
Screenshots
Does this MR meet the acceptance criteria?
Conformity
-
Documentation (if required) - will be added in a separate MR given the MR is already big -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Edited by Oswaldo Ferreira