Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SimpleJob docs regarding attribute changes #68

Merged
merged 2 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 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)
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