Module: Zeridion::Flare::Job
- Defined in:
- lib/zeridion_flare/worker/job.rb
Overview
Mixin marking a class as a Flare payload job. Include it, optionally set
defaults with the flare_options macro, and implement #perform:
class SendWelcomeEmail
include Zeridion::Flare::Job
queue: "email", max_attempts: 5, timeout: 120
def perform(payload, ctx)
return if ctx.cancelled?
return if AlreadySent.exists?(ctx.job_id) # at-least-once → idempotent
Mailer.welcome(payload["email"]).deliver_now
ctx.report_progress(1.0)
end
end
The included hook registers the class into the module-level worker
registry at definition time (no ObjectSpace scan). job_type defaults to the
class's fully-qualified name; override it with flare_options job_type:.
Two classes claiming the same job_type raise DuplicateJobTypeError.
payload is the decoded JSON Hash with STRING keys by default. Opt into a
typed payload with flare_options payload_struct: MyStruct — the worker
then calls MyStruct.new(**symbolized_hash) (works with Struct / Data /
any keyword-initializable class).
Defined Under Namespace
Modules: ClassMacros, InstanceShape
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
30 31 32 33 34 |
# File 'lib/zeridion_flare/worker/job.rb', line 30 def self.included(base) base.extend(ClassMacros) base.include(InstanceShape) Worker::Registry.register_payload(base) end |