From 43e1fa0552ca1b4e7e20879fd9b26e25650232d2 Mon Sep 17 00:00:00 2001 From: Fabio Perrella Date: Thu, 17 Dec 2020 09:24:38 +0100 Subject: [PATCH] Improve SimpleJob docs regarding attribute changes (#68) Co-authored-by: Martijn Vermaat --- 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..7998daa 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 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..ac9d236 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 class 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 or removing +# an attribute. +# This mechanism guarantees strong consistency. Without it, 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)