state_machine_job 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -6
- data/README.md +9 -3
- data/lib/state_machine_job.rb +1 -0
- data/lib/state_machine_job/version.rb +1 -1
- data/spec/state_machine_job_spec.rb +36 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1da48595f1508f1bcadd9c3f342893b1b2e902df7768c2bc84cde8047581b150
|
4
|
+
data.tar.gz: 46fe342256ddab39e39c233cd8036b60c8bb73cac2f1a9b456e1a92aca3965c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dce23a6e924e89b36c9a1d745be3f47643a058e0ac27337ac288bd348df876a3d6d51abc99311da82ab35e6e947e2fda88994566f2cfd6a0db967a6e86670bd3
|
7
|
+
data.tar.gz: 6cb757643ff20b9a18e29a875ca7f059a9cf6860faa40dea07f69384f2a9107a26638f18e2b02786c7dbde0777bafa9a12a47c0547697c072bf122bfa1a3cf37
|
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
### Version 3.
|
3
|
+
### Version 3.1.0
|
4
4
|
|
5
|
-
|
5
|
+
2019-07-22
|
6
6
|
|
7
|
-
[Compare changes](http://github.com/codevise/state_machine_job/compare/
|
7
|
+
[Compare changes](http://github.com/codevise/state_machine_job/compare/3-0-stable...v3.1.0)
|
8
8
|
|
9
|
-
-
|
10
|
-
([#
|
9
|
+
- Ensure error state can be persisted if job leaves record invalid.
|
10
|
+
([#11](https://github.com/codevise/state_machine_job/pull/11))
|
11
11
|
|
12
12
|
See
|
13
|
-
[
|
13
|
+
[3-0-stable branch](http://github.com/codevise/state_machine_job/blob/3-0-stable/CHANGELOG.md)
|
14
14
|
for previous changes.
|
data/README.md
CHANGED
@@ -56,9 +56,15 @@ When the `state` attribute changes to `'running'` (either by the `run`
|
|
56
56
|
event or by manually updateing the attribute), `SomeJob` will
|
57
57
|
automatically be enqueued. If `perform_with_result` returns `:ok`, the
|
58
58
|
state machine transitions to the `'done'` state. You can specify as
|
59
|
-
many results as you want.
|
60
|
-
|
61
|
-
|
59
|
+
many results as you want.
|
60
|
+
|
61
|
+
Note that any exception raised by `perform_with_result` leads to a
|
62
|
+
state machine transition as if the result had been `:error`. The
|
63
|
+
exception is not rescued, though. If `perform_with_result` raises an
|
64
|
+
exception and the record is invalid, previous attribute values will be
|
65
|
+
restored before invoking the transition. That way the transition to
|
66
|
+
the error state can be persisted by rolling back the changes that led
|
67
|
+
to the records invalidity during job execution.
|
62
68
|
|
63
69
|
### Passing custom Payload
|
64
70
|
|
data/lib/state_machine_job.rb
CHANGED
@@ -8,6 +8,9 @@ describe StateMachineJob do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
class Model
|
11
|
+
include ActiveModel::Dirty
|
12
|
+
include ActiveModel::Validations
|
13
|
+
|
11
14
|
def id
|
12
15
|
3
|
13
16
|
end
|
@@ -17,6 +20,23 @@ describe StateMachineJob do
|
|
17
20
|
def test_job_error!; end
|
18
21
|
end
|
19
22
|
|
23
|
+
class ModelRequiringName < Model
|
24
|
+
attr_reader :name
|
25
|
+
|
26
|
+
validates_presence_of :name
|
27
|
+
define_attribute_methods :name
|
28
|
+
|
29
|
+
def initialize(name: nil)
|
30
|
+
@name = name
|
31
|
+
changes_applied
|
32
|
+
end
|
33
|
+
|
34
|
+
def name=(value)
|
35
|
+
name_will_change! unless value == @name
|
36
|
+
@name = value
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
20
40
|
class SomeError < StandardError; end
|
21
41
|
|
22
42
|
it 'passes record and payload to perform_with_result method' do
|
@@ -61,4 +81,20 @@ describe StateMachineJob do
|
|
61
81
|
rescue SomeError # rubocop:disable Lint/HandleExceptions
|
62
82
|
end
|
63
83
|
end
|
84
|
+
|
85
|
+
it 'restores attributes of invalid record before invoking job result event ' \
|
86
|
+
'if perform_with_result raises to ensure state transition can be persisted' do
|
87
|
+
record = ModelRequiringName.new(name: 'Susan')
|
88
|
+
job = TestJob.new
|
89
|
+
|
90
|
+
record.name = ''
|
91
|
+
allow(job).to receive(:perform_with_result).and_raise(SomeError)
|
92
|
+
|
93
|
+
begin
|
94
|
+
job.perform(record)
|
95
|
+
rescue SomeError # rubocop:disable Lint/HandleExceptions
|
96
|
+
ensure
|
97
|
+
expect(record).to be_valid
|
98
|
+
end
|
99
|
+
end
|
64
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: state_machine_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Codevise Solutions Ltd.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: state_machines-activemodel
|