From 140d70fc30137bee54237019ea6b86bcc7373211 Mon Sep 17 00:00:00 2001 From: Fabio Perrella Date: Fri, 11 Dec 2020 15:00:56 +0100 Subject: [PATCH] Add more docs about SimpleJob and the process of adding or removing attributes --- README.md | 4 ++++ lib/sqewer/simple_job.rb | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cd467f5..40d10de 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,10 @@ Note that at this point only arguments that are raw JSON types are supported: If you need marshalable Ruby types there instead, you might need to implement a custom `Serializer.` +### Sqewer::SimpleJob + +The module `Sqewer::SimpleJob` can be included to a job class to add some features, specially dealing with the attributes, see more details [here](https://github.com/WeTransfer/sqewer/blob/master/lib/sqewer/simple_job.rb). + ## Jobs spawning dependent jobs If your `run` method on the job object accepts arguments (has non-zero `arity` ) the `ExecutionContext` will diff --git a/lib/sqewer/simple_job.rb b/lib/sqewer/simple_job.rb index 6f0a50e..483f59d 100644 --- a/lib/sqewer/simple_job.rb +++ b/lib/sqewer/simple_job.rb @@ -4,6 +4,13 @@ # * initialize() will have keyword access to all accessors, and will ensure you have called each one of them # * to_h() will produce a symbolized Hash with all the properties defined using attr_accessor, and the job_class_name # * inspect() will provide a sensible default string representation for logging +# +# This module validates if the attributes defined in the job are the same as +# those persisted in the queue. More details on `Sqewer::SimpleJob#initialize` +# Because of this, it's required to create a new job class when adding of removing +# an attribute. +# This mechanism guarantees a strong consistency otherwise, a new deployed job class +# could process old incompatible payloads. module Sqewer::SimpleJob UnknownJobAttribute = Class.new(Sqewer::Error) MissingAttribute = Class.new(Sqewer::Error) @@ -53,7 +60,7 @@ def initialize(**jobargs) accessor = "#{k}=" touched_attributes << k unless respond_to?(accessor) - raise UnknownJobAttribute, "Unknown attribute #{k.inspect} for #{self.class}" + raise UnknownJobAttribute, "Unknown attribute #{k.inspect} for #{self.class}" end send("#{k}=", v)