Cookbook¶
Real apps do not stop at “define a task and call work.” They need jobs, databases, auth, rate limits, and traces that make sense at 2 a.m.
These recipes are copy-paste starting points for wiring CMDx into a Rails app. Each page stands on its own — open the one closest to what you are building today.
How each recipe is laid out¶
Most pages follow the same rhythm so you can skim:
- Intro — what problem this solves and when to reach for it
- Setup — middleware, initializer, or helper you install once
- Usage — register it on a task and run an example
- What to expect — sample SQL, JSON, or
Resultshapes (when it helps) - Notes — gotchas and “pick this vs that” tips
Rails and Active Record¶
- Active Record Database Transaction — commit every write together, or roll back as a unit
- Active Record Query Tagging — stamp SQL with the task name and trace ids
- Paper Trail Whatdunnit — tell Paper Trail which task changed a record
API and integration¶
- GraphQL Resolvers — keep mutations thin; let tasks do the work
- OpenAPI Schema Generation — generate request schemas from task inputs
- PubSub Task Chaining — trigger follow-on work with domain events
Cross-cutting concerns¶
- Background Execution — run tasks on a queue with Active Job or Sidekiq
- Store Wrappers — test doubles and instrumented store wrappers
- Flipper Feature Flags — gate tasks behind feature flags
- Pundit Authorization — authorize before
workruns - Timeout Guard — cap how long a task may run
- Sentry Error Tracking — send failures to Sentry with context
- OpenTelemetry Tracing — one span per task, nested like your chain