← Graph

Prefer Prepend Over Inheritance For Jobs

takeaway 2 connections

Inheritance forces one parent; jobs that share overlapping (but not identical) concerns such as rescuing different combinations of errors end up with a huge, unmaintainable, untestable parent. Instead, define small modules that rescue specific errors and call super to invoke perform, and prepend them into each job class that needs them. prepend inserts the module before the class in the ancestor chain (unlike include), so the rescue wraps the original perform transparently. This keeps perform free of rescue code and lets each job compose exactly the handlers it needs.

type
recommendation
takeaway Prefer Prepend Over Inheritance For Jobs
about
Relies on Ruby's prepend vs include semantics for module composition.
takeaway Prefer Prepend Over Inheritance For Jobs
from_talk
Takeaway from the 'under the hood / on the surface' Sidekiq talk.

Provenance

Read by
2 extractions