Skip to content

Commit

Permalink
Add more docs about SimpleJob and the process of adding or removing a…
Browse files Browse the repository at this point in the history
…ttributes
  • Loading branch information
fabioperrella committed Dec 11, 2020
1 parent 28943e2 commit 140d70f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion lib/sqewer/simple_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 140d70f

Please sign in to comment.