Assessing Code for Idempotency
It’s extremely hard to assert that a piece of code is idempotent. What you want to do is examine the code triggered from a Sidekiq job and ask yourself what happens when that code fails and retries. A process that helps do this systematically is as follows:
-
For each line of code, N, mentally execute the code from line 1 to N, and then from line 1 to the end of the routine. Don’t worry about why the code stops at line N—just assume a gopher chewed through the server’s power cable and everything just stopped.
-
For each N, determine the state of the system after completing the first step.
-
If the state of the system is unacceptable, you’ve identified a likely issue when the Sidekiq job retries after failure. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access