simpler_workflow 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -169,6 +169,17 @@ You can also define similar hooks for events using the following methods:
169
169
  * ```on_activity_completed``` is called when an activity completes and SWF reports back to the decision loop.
170
170
  * ```on_activity_failed``` is called when an activity reports a failure to SWF.
171
171
 
172
+ ## Workflow and Activity Versioning
173
+
174
+ All workflow types and activity types are versioned under SWF. This allows an organization to release new versions of a workflow or activity
175
+ as they are updated and allow workflows to complete under the old version number if need be.
176
+
177
+ Here are a few recommendations on when to change the version of a workflow or activity when using SimplerWorkflow:
178
+
179
+ 1. You need to bump the version when you are changing the defaults associated with an activity or workflow. These are set using the ```default_``` methods. The defaults are commnicated to AWS when the workflow or activity is registered. It does not get updated when they are changed within the code.
180
+ 2. You may want to bump a version if you have work in progress under an existing workflow and you need to introduce changes for new work. You will need to keep the older activity and or workflow around while it completes.
181
+ 3. You do not need to bump the version when you change the work performed by the activity or the decision loop itself. This is code that is directly managed by SimplerWorkflow and isn't communicated to AWS. This only works if you do not want previous workflows to finish using the previous version of the code though.
182
+
172
183
  ## Contributing
173
184
 
174
185
  We welcome all kinds of contributions. This include code, fixes, issues, documentation, tests... Here's how you can contribute:
@@ -6,9 +6,9 @@ module SimplerWorkflow
6
6
  Activity.activities[[name, version]] ||= begin
7
7
  default_options = {
8
8
  :default_task_list => name,
9
- :default_task_start_to_close_timeout => 1 * 60 * 60,
9
+ :default_task_start_to_close_timeout => 5 * 60,
10
10
  :default_task_schedule_to_start_timeout => 5 * 60,
11
- :default_task_schedule_to_close_timeout => 1 * 60 * 60,
11
+ :default_task_schedule_to_close_timeout => 10 * 60,
12
12
  :default_task_heartbeat_timeout => :none
13
13
  }
14
14
  @options = default_options.merge(options)
@@ -4,18 +4,16 @@ module SimplerWorkflow
4
4
  domain_name = domain_name.to_s
5
5
  @domain = swf.domains[domain_name]
6
6
  unless swf.domains.include?(@domain)
7
- @domain = swf.domains.create(domain_name, retention)
7
+ @domain = swf.domains.create(domain_name, retention) rescue @domain
8
8
  end
9
9
 
10
- self.instance_eval(&block) if block
11
-
12
- self
10
+ self.instance_eval(&block) if block_given?
13
11
  end
14
12
 
15
13
  def Domain.domains(domain_name, &block)
16
14
  @domains ||= {}
17
15
  @domains[domain_name] ||= Domain.new(domain_name)
18
- @domains[domain_name].instance_eval(&block) if block
16
+ @domains[domain_name].instance_eval(&block) if block_given?
19
17
  @domains[domain_name]
20
18
  end
21
19
 
@@ -1,3 +1,3 @@
1
1
  module SimplerWorkflow
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -7,7 +7,7 @@ module SimplerWorkflow
7
7
  default_options = {
8
8
  :default_task_list => name,
9
9
  :default_task_start_to_close_timeout => 2 * 60,
10
- :default_execution_start_to_close_timeout => 1 * 24 * 60 * 60,
10
+ :default_execution_start_to_close_timeout => 2 * 60,
11
11
  :default_child_policy => :terminate
12
12
  }
13
13
  @options = default_options.merge(options)
@@ -39,6 +39,8 @@ module SimplerWorkflow
39
39
  activity_completed(decision_task, event)
40
40
  when 'ActivityTaskFailed'
41
41
  activity_failed(decision_task, event)
42
+ when 'ActivityTaskTimedOut'
43
+ activity_timed_out(decision_task, event)
42
44
  end
43
45
  end
44
46
  end
@@ -95,6 +97,21 @@ module SimplerWorkflow
95
97
  end
96
98
  end
97
99
 
100
+ def activity_timed_out(decision_task, event)
101
+ logger.info("Activity timed out.")
102
+ if @on_activity_timed_out && @on_activity_timed_out.respond_to?(:call)
103
+ @on_activity_timed_out.call(decision_task, event)
104
+ else
105
+ case event.attributes.timeoutType
106
+ when 'START_TO_CLOSE', 'SCHEDULE_TO_START', 'SCHEDULE_TO_CLOSE'
107
+ logger.info("Retrying activity #{last_activity(decision_task, event).name} #{last_activity(decision_task, event).version} due to timeout.")
108
+ decision_task.schedule_activity_task last_activity(decision_task, event), :input => last_input(decision_task, event)
109
+ when 'HEARTBEAT'
110
+ decision_task.cancel_workflow_execution
111
+ end
112
+ end
113
+ end
114
+
98
115
  def start_workflow(input, options = {})
99
116
  options[:input] = input
100
117
  domain.workflow_types[name.to_s, version].start_execution(options)
@@ -112,6 +129,10 @@ module SimplerWorkflow
112
129
  @on_activity_failed = block
113
130
  end
114
131
 
132
+ def on_activity_timed_out(&block)
133
+ @on_activity_timed_out = block
134
+ end
135
+
115
136
  def self.[](name, version)
116
137
  workflows[[name, version]]
117
138
  end
@@ -15,7 +15,8 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = SimplerWorkflow::VERSION
17
17
 
18
- gem.add_dependency 'aws-sdk', '~> 1.4.0'
18
+ gem.add_dependency 'aws-sdk', '~> 1.5.0'
19
19
  gem.add_dependency 'map'
20
+ gem.add_development_dependency 'rake'
20
21
  gem.add_development_dependency 'rspec'
21
22
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simpler_workflow
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Frederic Jean
@@ -15,28 +15,26 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-27 00:00:00 Z
18
+ date: 2012-05-24 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: aws-sdk
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
22
  none: false
25
23
  requirements:
26
24
  - - ~>
27
25
  - !ruby/object:Gem::Version
28
- hash: 7
26
+ hash: 3
29
27
  segments:
30
28
  - 1
31
- - 4
29
+ - 5
32
30
  - 0
33
- version: 1.4.0
31
+ version: 1.5.0
32
+ name: aws-sdk
34
33
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: map
38
34
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
38
  none: false
41
39
  requirements:
42
40
  - - ">="
@@ -45,12 +43,26 @@ dependencies:
45
43
  segments:
46
44
  - 0
47
45
  version: "0"
46
+ name: map
48
47
  type: :runtime
49
- version_requirements: *id002
48
+ prerelease: false
49
+ requirement: *id002
50
50
  - !ruby/object:Gem::Dependency
51
- name: rspec
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ name: rake
61
+ type: :development
52
62
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
63
+ requirement: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ version_requirements: &id004 !ruby/object:Gem::Requirement
54
66
  none: false
55
67
  requirements:
56
68
  - - ">="
@@ -59,8 +71,10 @@ dependencies:
59
71
  segments:
60
72
  - 0
61
73
  version: "0"
74
+ name: rspec
62
75
  type: :development
63
- version_requirements: *id003
76
+ prerelease: false
77
+ requirement: *id004
64
78
  description: A wrapper around Amazon's Simple Workflow Service
65
79
  email:
66
80
  - fred@snugghome.com