simpler_workflow 0.2.0 → 0.2.1

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.
@@ -52,8 +52,10 @@ module SimplerWorkflow
52
52
  logger.info("Performing task #{name}")
53
53
  @perform_task.call(task)
54
54
  rescue => e
55
- logger.error e.message
56
- logger.error e.backtrace.join("\n")
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
 
@@ -104,8 +106,11 @@ module SimplerWorkflow
104
106
  retry
105
107
  end
106
108
  rescue => e
107
- logger.error(e.message)
108
- logger.error(e.backtrace.join("\n"))
109
+ context = to_activity_type
110
+ context[:input] = task.input
111
+ context[:activity_id] = task.activity_id
112
+ SimplerWorkflow.exception_reporter.report(e, context)
113
+ raise e
109
114
  end
110
115
  end
111
116
  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
@@ -1,3 +1,3 @@
1
1
  module SimplerWorkflow
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -75,8 +75,15 @@ module SimplerWorkflow
75
75
  else
76
76
  retry
77
77
  end
78
+ rescue => e
79
+ context = {
80
+ :workflow_execution => decision_task.workflow_execution,
81
+ :workflow => to_workflow_type,
82
+ :decision_task => decision_task
83
+ }
84
+ SimplerWorkflow.exception_reporter.report(e, context)
85
+ raise e
78
86
  end
79
- nil
80
87
  end
81
88
  end
82
89
  end
@@ -145,6 +152,10 @@ module SimplerWorkflow
145
152
  end
146
153
  end
147
154
 
155
+ def to_workflow_type
156
+ { :name => name, :version => version }
157
+ end
158
+
148
159
  def start_workflow(input, options = {})
149
160
  options[:input] = input
150
161
  domain.workflow_types[name.to_s, version].start_execution(options)
@@ -38,11 +38,24 @@ module SimplerWorkflow
38
38
  @child_processes ||= []
39
39
  end
40
40
 
41
+ def exception_reporter(&block)
42
+ if block_given?
43
+ @exception_reporter = DefaultExceptionReporter.new(&block)
44
+ end
45
+
46
+ @exception_reporter || DefaultExceptionReporter.new
47
+ end
48
+
49
+ def exception_reporter=(exception_handler)
50
+ @exception_reporter = exception_handler
51
+ end
52
+
41
53
  autoload :Version, 'simpler_workflow/version'
42
54
  autoload :Domain, 'simpler_workflow/domain'
43
55
  autoload :Workflow, 'simpler_workflow/workflow'
44
56
  autoload :Activity, 'simpler_workflow/activity'
45
57
  autoload :OptionsAsMethods, 'simpler_workflow/options_as_methods'
58
+ autoload :DefaultExceptionReporter, 'simpler_workflow/default_exception_reporter'
46
59
  end
47
60
 
48
61
  class Map
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simpler_workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-22 00:00:00.000000000 Z
12
+ date: 2012-09-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -112,6 +112,7 @@ files:
112
112
  - lib/aws/simple_workflow/decision_task_additions.rb
113
113
  - lib/simpler_workflow.rb
114
114
  - lib/simpler_workflow/activity.rb
115
+ - lib/simpler_workflow/default_exception_reporter.rb
115
116
  - lib/simpler_workflow/domain.rb
116
117
  - lib/simpler_workflow/options_as_methods.rb
117
118
  - lib/simpler_workflow/tasks.rb
@@ -125,7 +126,7 @@ files:
125
126
  - spec/spec_helper.rb
126
127
  homepage: https://github.com/fredjean/simpler_workflow
127
128
  licenses: []
128
- post_install_message: ! "simpler_workflow 0.2.0\n========================\n\nHave
129
+ post_install_message: ! "simpler_workflow 0.2.1\n========================\n\nHave
129
130
  a look at https://github.com/fredjean/simpler_workflow/wiki/MIgrating-to-0.2.0 if
130
131
  you\nare upgrading from a 0.1.x version of the gem. There is a fundamental change
131
132
  in how the \nactivity and decision loops are run. You may need to adjust your application
@@ -140,18 +141,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
141
  - - ! '>='
141
142
  - !ruby/object:Gem::Version
142
143
  version: '0'
143
- segments:
144
- - 0
145
- hash: -1625844284378708087
146
144
  required_rubygems_version: !ruby/object:Gem::Requirement
147
145
  none: false
148
146
  requirements:
149
147
  - - ! '>='
150
148
  - !ruby/object:Gem::Version
151
149
  version: '0'
152
- segments:
153
- - 0
154
- hash: -1625844284378708087
155
150
  requirements: []
156
151
  rubyforge_project:
157
152
  rubygems_version: 1.8.23