Named ActiveJob class per service for async execution (v0.6.0) - #49
Merged
Conversation
Replace the single generic Servus::Extensions::Async::Job with a dedicated, named ActiveJob subclass generated per service (e.g. Treasury::TransferGold::Service => Treasury::TransferGold::ServiceJob), so background runners show a meaningful per-service job name instead of one generic class for every invocation. - Slim Async::Job to an abstract base bound to its service via a class_attribute; perform(**args) calls that service (the class itself identifies what to run). - call.rb owns the extension: call_async enqueues the service's named job with a clean perform_later(**args) payload; an async(queue:, priority:, &block) DSL exposes per-service ActiveJob config (block is class_eval'd for retry_on/etc.); an inherited hook generates the sibling job eagerly for named services, with a lazy servus_job_class accessor as the single memoization point. - Remove the now-unreachable ServiceNotFoundError (no name-based resolution). - Specs use stable global fixtures (no conditional teardown) and cover naming, worker-resolvability, the eager inherited path, and the async DSL. - Docs + CHANGELOG: public .call_async API is unchanged; document the async DSL and the upgrade notes (drain queues, workers must eager-load). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Release the named per-service async jobs and async(...) DSL. Minor bump under 0.x semver: new features alongside the documented breaking change to the async enqueue payload. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sync the lockfile to the bumped gemspec version so CI's frozen bundle install resolves. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Release: v0.6.0 — minor bump under 0.x semver (new features + a documented breaking change to the async enqueue payload).
What & why
Every async service invocation today runs through a single generic
Servus::Extensions::Async::Job. In job runners (Sidekiq, GoodJob, delayed_job, …) that means every background service shows up as the same class — so dashboards, per-queue metrics, retry tuning, and log filtering can't tell one service from another.This change generates a named ActiveJob class per service and adds a per-service
async(...)DSL for configuring the underlying ActiveJob options.What changed
Treasury::TransferGold::ServicegetsTreasury::TransferGold::ServiceJob, generated automatically.Async::Jobis now an abstract base bound to its service via aclass_attribute;perform(**args)calls that service (the class identifies what to run — nothing is resolved from a serialized name string).async(...)DSL —async queue: :critical, priority: 10for the common cases, plus anasync do … endblockclass_eval'd into the job for the full ActiveJob API (retry_on,discard_on, callbacks). Declared settings are class-level defaults; inline.call_asyncoptions layer on top per enqueue and win.inheritedhook creates the job eagerly for named services (worker-safe under Rails eager-load), with a lazyservus_job_classaccessor as the single memoization point.ServiceNotFoundError.Public API is unchanged
Service.call_async(user_id: 123, queue: :critical, wait: 5.minutes)works exactly as before.Upgrading (deployment notes, not code changes)
perform_later(name:, args:)toperform_later(**args); jobs enqueued by an older version won't run after the upgrade.Verification
call_spec/job_spec, addeddsl_spec; coverage for naming, worker-resolvability, the eagerinheritedpath, and the DSL (stable global fixtures, no conditional teardown).asyncconfig applied, cleanperform_later(**args)payload, inline queue override wins, inline execution runs the full lifecycle, and in aRAILS_ENV=productionprocesseager_load!alone defines each sibling job so it constantizes from its name string.Docs
site/features/async-execution.md— named jobs, theasyncDSL, eager-load note.CHANGELOG.md— 0.6.0 entry with upgrade notes.🤖 Generated with Claude Code