simpler_workflow 0.1.8 → 0.1.9
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.
data/lib/simpler_workflow.rb
CHANGED
@@ -18,11 +18,24 @@ module SimplerWorkflow
|
|
18
18
|
$logger || Rails.logger
|
19
19
|
end
|
20
20
|
|
21
|
+
def exception_reporter(&block)
|
22
|
+
if block_given?
|
23
|
+
@exception_reporter = DefaultExceptionReporter.new(&block)
|
24
|
+
end
|
25
|
+
|
26
|
+
@exception_reporter || DefaultExceptionReporter.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def exception_reporter=(exception_handler)
|
30
|
+
@exception_reporter = exception_handler
|
31
|
+
end
|
32
|
+
|
21
33
|
autoload :Version, 'simpler_workflow/version'
|
22
34
|
autoload :Domain, 'simpler_workflow/domain'
|
23
35
|
autoload :Workflow, 'simpler_workflow/workflow'
|
24
36
|
autoload :Activity, 'simpler_workflow/activity'
|
25
37
|
autoload :OptionsAsMethods, 'simpler_workflow/options_as_methods'
|
38
|
+
autoload :DefaultExceptionReporter, 'simpler_workflow/default_exception_reporter'
|
26
39
|
end
|
27
40
|
|
28
41
|
class Map
|
@@ -52,8 +52,10 @@ module SimplerWorkflow
|
|
52
52
|
logger.info("Performing task #{name}")
|
53
53
|
@perform_task.call(task)
|
54
54
|
rescue => e
|
55
|
-
|
56
|
-
|
55
|
+
context = to_activity_type
|
56
|
+
context[:input] = task.input
|
57
|
+
context[:activity_id] = task.activity_id
|
58
|
+
SimplerWorkflow.exception_reporter.report(e, context)
|
57
59
|
task.fail! :reason => e.message[0..250], :details => {:failure_policy => failure_policy}.to_json
|
58
60
|
end
|
59
61
|
|
@@ -80,8 +82,11 @@ module SimplerWorkflow
|
|
80
82
|
end
|
81
83
|
rescue Timeout::Error => e
|
82
84
|
rescue => e
|
83
|
-
|
84
|
-
|
85
|
+
context = to_activity_type
|
86
|
+
context[:input] = task.input
|
87
|
+
context[:activity_id] = task.activity_id
|
88
|
+
SimplerWorkflow.exception_reporter.report(e, context)
|
89
|
+
raise e
|
85
90
|
end
|
86
91
|
end
|
87
92
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Default exception handler. Just logs to the logger and re-raise
|
2
|
+
# so the exception can be managed as usual.
|
3
|
+
|
4
|
+
module SimplerWorkflow
|
5
|
+
class DefaultExceptionReporter
|
6
|
+
attr_accessor :reporter, :tag
|
7
|
+
|
8
|
+
def initialize(&block)
|
9
|
+
@reporter = block if block_given?
|
10
|
+
end
|
11
|
+
|
12
|
+
def report(e, context = {})
|
13
|
+
if reporter
|
14
|
+
reporter.call(e, context)
|
15
|
+
else
|
16
|
+
SimplerWorkflow.logger.error("[#{tag}] Exception: #{e.message}")
|
17
|
+
SimplerWorkflow.logger.error("[#{tag}] Context: #{context.inspect}") unless context.empty?
|
18
|
+
SimplerWorkflow.logger.error("[#{tag}] Backtrace:\n#{e.backtrace.join("\n")}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def tag
|
23
|
+
@tag || "SimplerWorkflow"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -31,23 +31,32 @@ module SimplerWorkflow
|
|
31
31
|
def decision_loop
|
32
32
|
logger.info("Starting decision loop for #{name.to_s}, #{version} listening to #{task_list}")
|
33
33
|
domain.decision_tasks.poll(task_list) do |decision_task|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
34
|
+
begin
|
35
|
+
start_time = DateTime.now
|
36
|
+
logger.info("Received decision task #{decision_task.id} at #{start_time}")
|
37
|
+
decision_task.extend AWS::SimpleWorkflow::DecisionTaskAdditions
|
38
|
+
decision_task.new_events.each do |event|
|
39
|
+
logger.info("Processing #{event.event_type}")
|
40
|
+
case event.event_type
|
41
|
+
when 'WorkflowExecutionStarted'
|
42
|
+
start_execution(decision_task, event)
|
43
|
+
when 'ActivityTaskCompleted'
|
44
|
+
activity_completed(decision_task, event)
|
45
|
+
when 'ActivityTaskFailed'
|
46
|
+
activity_failed(decision_task, event)
|
47
|
+
when 'ActivityTaskTimedOut'
|
48
|
+
activity_timed_out(decision_task, event)
|
49
|
+
end
|
48
50
|
end
|
51
|
+
rescue => e
|
52
|
+
context = {
|
53
|
+
:workflow_execution => decision_task.workflow_execution,
|
54
|
+
:workflow => to_workflow_type,
|
55
|
+
:decision_task => decision_task
|
56
|
+
}
|
57
|
+
SimplerWorkflow.exception_reporter.report(e, context)
|
58
|
+
raise e
|
49
59
|
end
|
50
|
-
logger.info("Completed Processing Decision Task #{decision_task.id} in #{((DateTime.now - start_time) * 24 * 60 * 60).to_i} seconds.")
|
51
60
|
end
|
52
61
|
rescue Timeout::Error => e
|
53
62
|
retry
|
@@ -117,6 +126,10 @@ module SimplerWorkflow
|
|
117
126
|
end
|
118
127
|
end
|
119
128
|
|
129
|
+
def to_workflow_type
|
130
|
+
{ :name => name, :version => version }
|
131
|
+
end
|
132
|
+
|
120
133
|
def start_workflow(input, options = {})
|
121
134
|
options[:input] = input
|
122
135
|
domain.workflow_types[name.to_s, version].start_execution(options)
|
metadata
CHANGED
@@ -1,104 +1,104 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: simpler_workflow
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.9
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 8
|
10
|
-
version: 0.1.8
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Frederic Jean
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
date: 2012-09-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: aws-sdk
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
22
17
|
none: false
|
23
|
-
requirements:
|
18
|
+
requirements:
|
24
19
|
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
hash: 3
|
27
|
-
segments:
|
28
|
-
- 1
|
29
|
-
- 5
|
30
|
-
- 0
|
20
|
+
- !ruby/object:Gem::Version
|
31
21
|
version: 1.5.0
|
32
|
-
name: aws-sdk
|
33
22
|
type: :runtime
|
34
23
|
prerelease: false
|
35
|
-
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
version_requirements: &id002 !ruby/object:Gem::Requirement
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
25
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
|
44
|
-
- 0
|
45
|
-
version: "0"
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.5.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
46
31
|
name: map
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
47
38
|
type: :runtime
|
48
39
|
prerelease: false
|
49
|
-
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
41
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
|
58
|
-
- 0
|
59
|
-
version: "0"
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
60
47
|
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
61
54
|
type: :development
|
62
55
|
prerelease: false
|
63
|
-
|
64
|
-
- !ruby/object:Gem::Dependency
|
65
|
-
version_requirements: &id004 !ruby/object:Gem::Requirement
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
57
|
none: false
|
67
|
-
requirements:
|
68
|
-
- -
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
|
71
|
-
|
72
|
-
- 0
|
73
|
-
version: "0"
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
74
63
|
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
75
70
|
type: :development
|
76
71
|
prerelease: false
|
77
|
-
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
version_requirements: &id005 !ruby/object:Gem::Requirement
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
73
|
none: false
|
81
|
-
requirements:
|
82
|
-
- -
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
|
85
|
-
|
86
|
-
- 0
|
87
|
-
version: "0"
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
88
79
|
name: travis-lint
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
89
86
|
type: :development
|
90
87
|
prerelease: false
|
91
|
-
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
92
94
|
description: A wrapper around Amazon's Simple Workflow Service
|
93
|
-
email:
|
95
|
+
email:
|
94
96
|
- fred@snugghome.com
|
95
|
-
executables:
|
97
|
+
executables:
|
96
98
|
- swf
|
97
99
|
extensions: []
|
98
|
-
|
99
100
|
extra_rdoc_files: []
|
100
|
-
|
101
|
-
files:
|
101
|
+
files:
|
102
102
|
- .gitignore
|
103
103
|
- .rspec
|
104
104
|
- .travis.yml
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/aws/simple_workflow/decision_task_additions.rb
|
112
112
|
- lib/simpler_workflow.rb
|
113
113
|
- lib/simpler_workflow/activity.rb
|
114
|
+
- lib/simpler_workflow/default_exception_reporter.rb
|
114
115
|
- lib/simpler_workflow/domain.rb
|
115
116
|
- lib/simpler_workflow/options_as_methods.rb
|
116
117
|
- lib/simpler_workflow/version.rb
|
@@ -122,38 +123,30 @@ files:
|
|
122
123
|
- spec/spec_helper.rb
|
123
124
|
homepage: https://github.com/SnuggHome/simpler_workflow
|
124
125
|
licenses: []
|
125
|
-
|
126
126
|
post_install_message:
|
127
127
|
rdoc_options: []
|
128
|
-
|
129
|
-
require_paths:
|
128
|
+
require_paths:
|
130
129
|
- lib
|
131
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
131
|
none: false
|
133
|
-
requirements:
|
134
|
-
- -
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
|
137
|
-
|
138
|
-
- 0
|
139
|
-
version: "0"
|
140
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
137
|
none: false
|
142
|
-
requirements:
|
143
|
-
- -
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
|
146
|
-
segments:
|
147
|
-
- 0
|
148
|
-
version: "0"
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
149
142
|
requirements: []
|
150
|
-
|
151
143
|
rubyforge_project:
|
152
|
-
rubygems_version: 1.8.
|
144
|
+
rubygems_version: 1.8.23
|
153
145
|
signing_key:
|
154
146
|
specification_version: 3
|
155
|
-
summary: A wrapper and DSL around Amazon's Simple Workflow Service with the goal of
|
156
|
-
|
147
|
+
summary: A wrapper and DSL around Amazon's Simple Workflow Service with the goal of
|
148
|
+
making it almost pleasant to define workflows.
|
149
|
+
test_files:
|
157
150
|
- spec/domain_spec.rb
|
158
151
|
- spec/simpler_workflow_spec.rb
|
159
152
|
- spec/spec_helper.rb
|