state_machine_job 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZGViMzAyYTY5MDM0ODM1YTEyZWQ4ODI5OGMyMjE1NWUxYjcwYTQzYQ==
5
- data.tar.gz: !binary |-
6
- NTlhMzgwNzk4OWJhZDNjMWE1YWJmOTAyOWIwNzkxOGZlZWYxMDY1OA==
2
+ SHA1:
3
+ metadata.gz: 399f472130b3ee8015808ca3295f2802c5610bce
4
+ data.tar.gz: 038d38a55ee2d05627a6a0392d3e957bb1ab06b6
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NmQ4NjU2Mzc0NjZiOThjMmVkYTkwODYzYTQwZmVhZGFhNWNmNmM1ZDAxNzUz
10
- NDJiNDVlY2VmMjY4OWVmYzUwYmE2MWMzYjA4OTk4NjEyNzc3ZjIyZTU2MjA0
11
- M2VlNmUxNjRmNzdmM2NkZGNkOTZmYjhjMmUwMTNlZmFkZGQ5ZjY=
12
- data.tar.gz: !binary |-
13
- YzFjNDZhYWU4YmNkYjMzMGI3ZDE3NmY2NmQ5YjI1ZGU5Mjk5ODY4NzZmNGQ4
14
- MWM1OWIyNzhjZDAzMDA5NjMwMzdhZWM4NGU4M2EzY2U5YjE0YzRhODg1NzAy
15
- MDdhOWRkODI4ZDUyYjVlOGZlNTRmYWI2M2JiZjBiOTA1ZTViNDM=
6
+ metadata.gz: 2eca4e96a81540fc28e25cfa7bd005478254b434cc0a78f04489c94f529da5796260f14d477e04bb857b2ee3f78b7430a8f87b0f06006788a7f6fe8b03c67659
7
+ data.tar.gz: 94668d80123330fa26e56ecc1e4c1918c46afff64d3afae6ad953a010273458ac69279204d7ad9454edf3d94117adc931cd16588ce86ded59adf0b1a3aeb7d0d
@@ -1,4 +1,4 @@
1
1
  rvm:
2
- - 1.9.3
2
+ - 2.1.0
3
3
 
4
4
  script: "bundle exec rspec"
@@ -1,13 +1,24 @@
1
1
  # CHANGELOG
2
2
 
3
- ### Version 0.2.0
3
+ ### Version 1.0.0
4
4
 
5
- * `:if` option for job `result` to change to different states based on
6
- conditionals.
7
- * Raise an exception if the shorthand `result` signature is used with
8
- further options which would be ignored.
5
+ 2017-08-02
9
6
 
10
- ### Version 0.1.0
7
+ [Compare changes](http://github.com/codevise/state_machine_job/compare/0-x-stable...v1.0.0)
11
8
 
12
- * `:retry_if_state` option to rerun jobs on completion if the state
13
- changed since the job was scheduled.
9
+ - Do not silence exceptions. Ensure state machine can transition to
10
+ failed state by invoking error result event, but then re-raise
11
+ exception, so they show up in the Resque error list. Jobs are still
12
+ free to rescue exceptions themselves and return an error result
13
+ instead.
14
+ ([#5](https://github.com/codevise/state_machine_job/pull/5))
15
+ - Add backtrace info to exception logging
16
+ ([#3](https://github.com/codevise/state_machine_job/pull/3))
17
+ - Restrict activesupport to < 5 for now
18
+ ([#4](https://github.com/codevise/state_machine_job/pull/4))
19
+ - Use sinatra 1 in development and tests for ruby 2.1 compatibility
20
+ ([#6](https://github.com/codevise/state_machine_job/pull/6))
21
+
22
+ See
23
+ [0-x-stable branch](https://github.com/codevise/state_machine_job/blob/0-x-stable/CHANGELOG.md)
24
+ for previous changes.
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in state_machine_job.gemspec
4
4
  gemspec
5
+
6
+ # Sinatra 2 requires Ruby 2.2
7
+ gem 'sinatra', '~> 1.0'
data/README.md CHANGED
@@ -83,7 +83,7 @@ method using the `payload` method:
83
83
  `perform_with_result` is now called with the given hash of options as
84
84
  the second parameter.
85
85
 
86
- ### Changing to States With Conditions
86
+ ### Changing to States with Conditions
87
87
 
88
88
  One job result can lead to different states based on a conditional.
89
89
  When the job finishes with the given result, the state machine
@@ -99,7 +99,7 @@ transitions to the first state whose conditional evaluates to true.
99
99
  result :error => 'failed'
100
100
  end
101
101
 
102
- A conditional can either be a lambda which optionally accepting the
102
+ A conditional can either be a lambda optionally accepting the
103
103
  record as parameter or a symbol specifying a method to call on the
104
104
  record.
105
105
 
data/Rakefile CHANGED
@@ -1 +1,4 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'semmy'
4
+ Semmy::Tasks.install
@@ -14,16 +14,19 @@ module StateMachineJob
14
14
  record = model_name.constantize.find_by_id(id)
15
15
 
16
16
  if record
17
- result =
18
- begin
19
- perform_with_result(record, payload)
20
- rescue Exception => e
21
- logger.error "#{self.name} - exception for #{model_name} #{id}: #{e.inspect}"
22
- :error
23
- end
24
-
25
- logger.info "#{self.name} - result #{result} for #{model_name} #{id}"
26
- record.send(event_name(result))
17
+ begin
18
+ result = perform_with_result(record, payload)
19
+ rescue Exception => e
20
+ result = :error
21
+
22
+ logger.error "#{self.name} - exception for #{model_name} #{id}: #{e.inspect}"
23
+ e.backtrace.each { |line| logger.info(line) }
24
+
25
+ raise
26
+ ensure
27
+ logger.info "#{self.name} - result #{result} for #{model_name} #{id}"
28
+ record.send(event_name(result))
29
+ end
27
30
  else
28
31
  logger.info "#{self.name} - #{model_name} #{id} not found. Skipping job."
29
32
  end
@@ -1,3 +1,3 @@
1
1
  module StateMachineJob
2
- VERSION = '0.2.0'
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -21,6 +21,8 @@ describe StateMachineJob do
21
21
  extend StateMachineJob
22
22
  end
23
23
 
24
+ class SomeError < StandardError; end
25
+
24
26
  class Model
25
27
  state_machine :initial => :idle do
26
28
  extend StateMachineJob::Macro
@@ -29,6 +31,7 @@ describe StateMachineJob do
29
31
  state :first_running
30
32
  state :second_running
31
33
  state :done
34
+ state :failed
32
35
 
33
36
  event :run do
34
37
  transition :idle => :first_running
@@ -40,6 +43,7 @@ describe StateMachineJob do
40
43
  {:n => 1}
41
44
  end
42
45
  result :ok => :second_running
46
+ result :error => :failed
43
47
  end
44
48
 
45
49
  job TestJob2, TestQueue.instance do
@@ -48,6 +52,7 @@ describe StateMachineJob do
48
52
  {:n => 2}
49
53
  end
50
54
  result :ok => :done
55
+ result :error => :failed
51
56
  end
52
57
  end
53
58
  end
@@ -76,6 +81,33 @@ describe StateMachineJob do
76
81
  model.run
77
82
  end
78
83
 
84
+ it 'lets exception bubble raised by perform_with_result' do
85
+ model = Model.new
86
+
87
+ allow(model).to receive(:id).and_return(5)
88
+ allow(Model).to receive(:find_by_id).and_return(model)
89
+ allow(TestJob1).to receive(:perform_with_result).and_raise(SomeError)
90
+
91
+ expect {
92
+ model.run
93
+ }.to raise_error(SomeError)
94
+ end
95
+
96
+ it 'invokes error job result event on record if perform_with_result raises' do
97
+ model = Model.new
98
+
99
+ allow(model).to receive(:id).and_return(5)
100
+ allow(Model).to receive(:find_by_id).and_return(model)
101
+ allow(TestJob1).to receive(:perform_with_result).and_raise(SomeError)
102
+
103
+ expect(model).to receive(:test_job1_error!)
104
+
105
+ begin
106
+ model.run
107
+ rescue SomeError
108
+ end
109
+ end
110
+
79
111
  it 'job is skipped if record cannot be found' do
80
112
  allow(Model).to receive(:find_by_id).and_return(nil)
81
113
 
@@ -11,6 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.description = %q{State Machine + Resque.}
12
12
  spec.summary = %q{Resque jobs class for rails state machines.}
13
13
  spec.homepage = "http://github.com/codevise/state_machine_job"
14
+ spec.licenses = ['MIT']
14
15
 
15
16
  spec.files = `git ls-files`.split($/)
16
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -18,11 +19,12 @@ Gem::Specification.new do |spec|
18
19
  spec.require_paths = ["lib"]
19
20
 
20
21
  spec.add_development_dependency 'bundler', '~> 1.3'
21
- spec.add_development_dependency 'rake'
22
- spec.add_development_dependency 'rspec'
23
- spec.add_development_dependency 'activesupport'
22
+ spec.add_development_dependency 'rake', '< 13'
23
+ spec.add_development_dependency 'rspec', '~> 3.6'
24
+ spec.add_development_dependency 'activesupport', '< 5'
25
+ spec.add_development_dependency 'semmy', '~> 1.0'
24
26
 
25
- spec.add_runtime_dependency 'resque'
26
- spec.add_runtime_dependency 'resque-logger'
27
- spec.add_runtime_dependency 'state_machine'
27
+ spec.add_runtime_dependency 'resque', '~> 1.25'
28
+ spec.add_runtime_dependency 'resque-logger', '~> 0.2.0'
29
+ spec.add_runtime_dependency 'state_machine', '~> 1.2'
28
30
  end
metadata CHANGED
@@ -1,113 +1,127 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_machine_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.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: 2014-07-01 00:00:00.000000000 Z
11
+ date: 2017-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '13'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - "<"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '13'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3.6'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '3.6'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activesupport
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - "<"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - "<"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: semmy
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: resque
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ! '>='
87
+ - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0'
89
+ version: '1.25'
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ! '>='
94
+ - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0'
96
+ version: '1.25'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: resque-logger
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - ! '>='
101
+ - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0'
103
+ version: 0.2.0
90
104
  type: :runtime
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - ! '>='
108
+ - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0'
110
+ version: 0.2.0
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: state_machine
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ! '>='
115
+ - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '0'
117
+ version: '1.2'
104
118
  type: :runtime
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - ! '>='
122
+ - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '0'
124
+ version: '1.2'
111
125
  description: State Machine + Resque.
112
126
  email:
113
127
  - info@codevise.de
@@ -115,8 +129,8 @@ executables: []
115
129
  extensions: []
116
130
  extra_rdoc_files: []
117
131
  files:
118
- - .gitignore
119
- - .travis.yml
132
+ - ".gitignore"
133
+ - ".travis.yml"
120
134
  - CHANGELOG.md
121
135
  - Gemfile
122
136
  - LICENSE.txt
@@ -131,7 +145,8 @@ files:
131
145
  - spec/support/setup_resque_logger.rb
132
146
  - state_machine_job.gemspec
133
147
  homepage: http://github.com/codevise/state_machine_job
134
- licenses: []
148
+ licenses:
149
+ - MIT
135
150
  metadata: {}
136
151
  post_install_message:
137
152
  rdoc_options: []
@@ -139,17 +154,17 @@ require_paths:
139
154
  - lib
140
155
  required_ruby_version: !ruby/object:Gem::Requirement
141
156
  requirements:
142
- - - ! '>='
157
+ - - ">="
143
158
  - !ruby/object:Gem::Version
144
159
  version: '0'
145
160
  required_rubygems_version: !ruby/object:Gem::Requirement
146
161
  requirements:
147
- - - ! '>='
162
+ - - ">="
148
163
  - !ruby/object:Gem::Version
149
164
  version: '0'
150
165
  requirements: []
151
166
  rubyforge_project:
152
- rubygems_version: 2.2.2
167
+ rubygems_version: 2.6.8
153
168
  signing_key:
154
169
  specification_version: 4
155
170
  summary: Resque jobs class for rails state machines.