fluere 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,5 @@
1
1
  require 'aws/decider'
2
2
 
3
- require 'fluere/activity'
4
3
  require 'fluere/config'
5
4
  require 'fluere/exceptions'
6
5
  require 'fluere/version'
@@ -16,6 +15,14 @@ module Fluere
16
15
  @workflows ||= []
17
16
  end
18
17
 
18
+ def self.decisions_task_list
19
+ Fluere.prefixed_task_list('decisions')
20
+ end
21
+
22
+ def self.activities_task_list
23
+ Fluere.prefixed_task_list('activities')
24
+ end
25
+
19
26
  def self.activities
20
27
  @activities ||= []
21
28
  end
@@ -51,8 +58,7 @@ module Fluere
51
58
  def self.start_execution(klass, *args)
52
59
  if stubbed?
53
60
  if perform_executions?
54
- method = klass.workflows.first.options.execution_method.to_sym
55
- klass.new.send(method, *args)
61
+ klass.decider_class.new.send(Fluere::Workflow::EXECUTION_METHOD, *args)
56
62
  end
57
63
  else
58
64
  klass.workflow_client.start_execution(*args)
@@ -1,3 +1,3 @@
1
1
  module Fluere
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -40,7 +40,7 @@ module Fluere
40
40
 
41
41
  class Workflow < Base
42
42
  def task_list
43
- Fluere.prefixed_task_list('decisions')
43
+ Fluere.decisions_task_list
44
44
  end
45
45
 
46
46
  def worker_class
@@ -54,7 +54,7 @@ module Fluere
54
54
 
55
55
  class Activity < Base
56
56
  def task_list
57
- Fluere.prefixed_task_list('activities')
57
+ Fluere.activities_task_list
58
58
  end
59
59
 
60
60
  def worker_class
@@ -1,66 +1,91 @@
1
1
  module Fluere
2
2
  module Workflow
3
+ EXECUTION_METHOD = :run
4
+
3
5
  def decider(&block)
4
- const_set('Decider', Class.new {
5
- extend AWS::Flow::Workflows
6
+ # Set the provided block as the workflow execution method
7
+ decider_class.send :define_method, EXECUTION_METHOD, &block
6
8
 
7
- def self.aws_name
8
- name.gsub(/:/, '_')
9
- end
10
- })
9
+ # Wire that method in as an AWS Flow workflow
10
+ decider_class.workflow(EXECUTION_METHOD) {
11
+ Fluere.default_workflow_options.merge(
12
+ prefix_name: decider_class.aws_name,
13
+ version: Fluere::Config.version,
14
+ )
15
+ }
11
16
 
12
- decider_class.send :define_method, :run, &block
13
- decider_class.workflow(:run) { Fluere.default_workflow_options.merge(
14
- prefix_name: decider_class.aws_name,
15
- version: Fluere::Config.version,
16
- default_task_list: Fluere.prefixed_task_list('decisions'),
17
- )}
17
+ # Give the decider a direct reference to activities for use in stubbed
18
+ # implementations
19
+ activities_class.tap do |klass|
20
+ decider_class.send(:define_method, :activities_class) { klass }
21
+ end
18
22
 
19
- Fluere.workflows << decider_class
23
+ # Establish the activity client which will be used in defining the helper
24
+ # method for each activity (when we are not stubbed)
25
+ decider_class.activity_client(:activities_client) {{
26
+ prefix_name: activities_class.aws_name,
27
+ version: Fluere::Config.version,
28
+ task_list: Fluere.activities_task_list
29
+ }}
20
30
  end
21
31
 
22
32
  def activity(name, &block)
23
- define_activities_class unless defined? Activities
24
- activities_class.activity(name) { Fluere.default_activity_options.merge(
25
- prefix_name: activities_class.aws_name,
26
- version: Fluere::Config.version,
27
- default_task_list: Fluere.prefixed_task_list('activities'),
28
- )}
33
+ # Define a method to be used as the activity implementation
29
34
  activities_class.send :define_method, name, &block
30
- define_activity_client unless decider_class.respond_to? :activities
35
+
36
+ # Wire this method in as an AWS Flow activity
37
+ activities_class.activity(name) {
38
+ Fluere.default_activity_options.merge(
39
+ prefix_name: activities_class.aws_name,
40
+ version: Fluere::Config.version,
41
+ )
42
+ }
43
+
44
+ # Establish a shortcut method for the decider implementation to use to
45
+ # call this activity as though it were a local method
31
46
  decider_class.send :define_method, name do |*args|
32
- activities.send(name, *args)
47
+ if Fluere.stubbed?
48
+ activities_class.new.send(name, *args)
49
+ else
50
+ activities_client.send(name, *args)
51
+ end
33
52
  end
34
53
  end
35
54
 
36
55
  def activities_class
37
- @activities_class ||= const_get('Activities')
38
- end
56
+ @activities_class ||= const_set('Activities', Class.new {
57
+ extend AWS::Flow::Activities
39
58
 
40
- def decider_class
41
- @decider_class ||= const_get('Decider')
59
+ # Stupid AWS doesn't allow colons in workflow or activity type names...
60
+ def self.aws_name
61
+ name.gsub(/:/, '_')
62
+ end
63
+ }).tap { |a| Fluere.activities << a }
42
64
  end
43
65
 
44
- def define_activities_class
45
- const_set('Activities', Class.new {
46
- extend AWS::Flow::Activities
66
+ def decider_class
67
+ @decider_class ||= const_set('Decider', Class.new {
68
+ extend AWS::Flow::Workflows
47
69
 
70
+ # Stupid AWS doesn't allow colons in workflow or activity type names...
48
71
  def self.aws_name
49
72
  name.gsub(/:/, '_')
50
73
  end
51
- })
52
- Fluere.activities << activities_class
53
- end
54
74
 
55
- def define_activity_client
56
- decider_class.activity_client(:activities) {{
57
- prefix_name: activities_class.aws_name,
58
- version: Fluere::Config.version
59
- }}
60
- end
75
+ def send_async(*args)
76
+ if Fluere.stubbed?
77
+ activities_class.new.send(*args)
78
+ else
79
+ activities_client.send_async(*args)
80
+ end
81
+ end
61
82
 
62
- def start_execution(*args)
63
- workflow_client.start_execution(:run, *args)
83
+ def wait_for_all(*args)
84
+ unless Fluere.stubbed?
85
+ super
86
+ end
87
+ end
88
+ }).tap { |d| Fluere.workflows << d }
64
89
  end
65
90
 
66
91
  def workflow_client
@@ -68,9 +93,10 @@ module Fluere
68
93
  Fluere.swf.client,
69
94
  Fluere.domain
70
95
  ) {{
71
- workflow_name: decider_class.aws_name,
72
- execution_method: "run",
73
- version: Fluere::Config.version,
96
+ workflow_name: decider_class.aws_name,
97
+ execution_method: EXECUTION_METHOD,
98
+ version: Fluere::Config.version,
99
+ task_list: Fluere.decisions_task_list
74
100
  }}
75
101
  end
76
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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: 2013-12-11 00:00:00.000000000 Z
12
+ date: 2013-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler