ntswf 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -0
- data/lib/ntswf/decision_worker.rb +37 -35
- metadata +1 -1
data/README.md
CHANGED
@@ -6,6 +6,9 @@ Not That Simple Workflow - A layer around AWS SWF
|
|
6
6
|
Common denominator of our [infopark](http://infopark.com/) internal services using
|
7
7
|
AWS Simple Workflow.
|
8
8
|
|
9
|
+
[![Gem Version](https://badge.fury.io/rb/ntswf.png)](http://badge.fury.io/rb/ntswf)
|
10
|
+
[![Code Climate](https://codeclimate.com/github/infopark/ntswf.png)](https://codeclimate.com/github/infopark/ntswf)
|
11
|
+
|
9
12
|
Usage
|
10
13
|
-----
|
11
14
|
### Gemfile
|
@@ -17,41 +17,7 @@ module Ntswf
|
|
17
17
|
domain.decision_tasks.poll_for_single_task(decision_task_list) do |task|
|
18
18
|
announce("got decision task #{task.workflow_execution.inspect}")
|
19
19
|
begin
|
20
|
-
task.new_events.each
|
21
|
-
log("processing event #{event.inspect}")
|
22
|
-
case event.event_type
|
23
|
-
when 'WorkflowExecutionStarted'
|
24
|
-
schedule(task, event)
|
25
|
-
when 'TimerFired'
|
26
|
-
start_event = task.events.first
|
27
|
-
keys = [
|
28
|
-
:child_policy,
|
29
|
-
:execution_start_to_close_timeout,
|
30
|
-
:input,
|
31
|
-
:tag_list,
|
32
|
-
:task_list,
|
33
|
-
:task_start_to_close_timeout,
|
34
|
-
]
|
35
|
-
attributes = start_event.attributes.to_h.keep_if {|k| keys.include? k}
|
36
|
-
task.continue_as_new_workflow_execution(attributes)
|
37
|
-
when 'ActivityTaskCompleted'
|
38
|
-
result = parse_result(event.attributes.result)
|
39
|
-
start_timer(task, result[:seconds_until_retry]) or task.complete_workflow_execution(
|
40
|
-
result: event.attributes.result)
|
41
|
-
when 'ActivityTaskFailed'
|
42
|
-
if (event.attributes.reason == RETRY)
|
43
|
-
schedule(task, task.events.first)
|
44
|
-
else
|
45
|
-
start_timer(task) or task.fail_workflow_execution(
|
46
|
-
event.attributes.to_h.slice(:details, :reason))
|
47
|
-
end
|
48
|
-
when 'ActivityTaskTimedOut'
|
49
|
-
notify("Timeout in Simple Workflow. Possible cause: all workers busy",
|
50
|
-
workflow_execution: task.workflow_execution.inspect)
|
51
|
-
start_timer(task) or task.cancel_workflow_execution(
|
52
|
-
details: 'activity task timeout')
|
53
|
-
end
|
54
|
-
end
|
20
|
+
task.new_events.each { |event| process_decision_event(task, event) }
|
55
21
|
rescue => e
|
56
22
|
notify(e, workflow_execution: task.workflow_execution.inspect)
|
57
23
|
raise e
|
@@ -61,6 +27,42 @@ module Ntswf
|
|
61
27
|
|
62
28
|
protected
|
63
29
|
|
30
|
+
def process_decision_event(task, event)
|
31
|
+
log("processing event #{event.inspect}")
|
32
|
+
case event.event_type
|
33
|
+
when 'WorkflowExecutionStarted'
|
34
|
+
schedule(task, event)
|
35
|
+
when 'TimerFired'
|
36
|
+
start_event = task.events.first
|
37
|
+
keys = [
|
38
|
+
:child_policy,
|
39
|
+
:execution_start_to_close_timeout,
|
40
|
+
:input,
|
41
|
+
:tag_list,
|
42
|
+
:task_list,
|
43
|
+
:task_start_to_close_timeout,
|
44
|
+
]
|
45
|
+
attributes = start_event.attributes.to_h.keep_if {|k| keys.include? k}
|
46
|
+
task.continue_as_new_workflow_execution(attributes)
|
47
|
+
when 'ActivityTaskCompleted'
|
48
|
+
result = parse_result(event.attributes.result)
|
49
|
+
start_timer(task, result[:seconds_until_retry]) or task.complete_workflow_execution(
|
50
|
+
result: event.attributes.result)
|
51
|
+
when 'ActivityTaskFailed'
|
52
|
+
if (event.attributes.reason == RETRY)
|
53
|
+
schedule(task, task.events.first)
|
54
|
+
else
|
55
|
+
start_timer(task) or task.fail_workflow_execution(
|
56
|
+
event.attributes.to_h.slice(:details, :reason))
|
57
|
+
end
|
58
|
+
when 'ActivityTaskTimedOut'
|
59
|
+
notify("Timeout in Simple Workflow. Possible cause: all workers busy",
|
60
|
+
workflow_execution: task.workflow_execution.inspect)
|
61
|
+
start_timer(task) or task.cancel_workflow_execution(
|
62
|
+
details: 'activity task timeout')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
64
66
|
def start_timer(task, interval = nil)
|
65
67
|
unless interval
|
66
68
|
options = parse_input(task.events.first.attributes.input)
|