fluere 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluere.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Paul Hinze
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Fluere
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fluere'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fluere
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = 'test/**/*_test.rb'
6
+ t.libs << 'test'
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fluere/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fluere"
8
+ spec.version = Fluere::VERSION
9
+ spec.authors = ['Paul Hinze']
10
+ spec.email = ['paulh@instructure.com']
11
+ spec.description = %q{A an elegant aws-flow adapter}
12
+ spec.summary = %q{A wrapper around aws-flow that makes it easier to work with}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'minitest', '~> 5.0'
24
+
25
+ spec.add_dependency 'aws-flow'
26
+ end
@@ -0,0 +1,77 @@
1
+ require 'aws/decider'
2
+
3
+ require 'fluere/activity'
4
+ require 'fluere/config'
5
+ require 'fluere/exceptions'
6
+ require 'fluere/version'
7
+ require 'fluere/worker'
8
+ require 'fluere/workflow'
9
+
10
+ module Fluere
11
+ def self.configure(&block)
12
+ yield Fluere::Config
13
+ end
14
+
15
+ def self.workflows
16
+ @workflows ||= []
17
+ end
18
+
19
+ def self.swf
20
+ @swf ||= AWS::SimpleWorkflow.new
21
+ end
22
+
23
+ def self.domain
24
+ swf.domains[Config.domain]
25
+ end
26
+
27
+ def self.prefixed_task_list(task_list)
28
+ [Fluere::Config.task_list_prefix, task_list].join
29
+ end
30
+
31
+ def self.start_execution(klass, *args)
32
+ if stubbed?
33
+ if perform_executions?
34
+ method = klass.workflows.first.options.execution_method.to_sym
35
+ klass.new.send(method, *args)
36
+ end
37
+ else
38
+ klass.workflow_client.start_execution(*args)
39
+ end
40
+ end
41
+
42
+ def self.flush!
43
+ domain.workflow_executions.with_status(:open).map { |we| we.terminate }
44
+ end
45
+
46
+ def self.stubbed?
47
+ @stubbed
48
+ end
49
+
50
+ def self.stub!
51
+ @stubbed = true
52
+ end
53
+
54
+ def self.unstub!
55
+ @stubbed = false
56
+ end
57
+
58
+ def self.assert_stubbed
59
+ raise StubbedPathOnlyError.new unless stubbed?
60
+ end
61
+
62
+ def self.perform_executions?
63
+ !ignore_executions?
64
+ end
65
+
66
+ def self.ignore_executions?
67
+ @ignore_executions
68
+ end
69
+
70
+ def self.ignore_executions
71
+ raise "only allowed to ignore executions when stubbed!" unless stubbed?
72
+ @ignore_executions = true
73
+ yield
74
+ ensure
75
+ @ignore_executions = false
76
+ end
77
+ end
@@ -0,0 +1,30 @@
1
+ module Fluere
2
+ module Activity
3
+ def self.extended(base)
4
+ base.extend AWS::Flow::Activities
5
+ base.extend ClassOverrides
6
+ base.send(:include, InstanceOverrides)
7
+ end
8
+
9
+ def fluere_worker_klass
10
+ AWS::Flow::ActivityWorker
11
+ end
12
+
13
+ module ClassOverrides
14
+ def activity(name, &block)
15
+ super(name) do
16
+ block.call.tap do |activity_options|
17
+ activity_options[:task_list] = Fluere.prefixed_task_list(activity_options[:default_task_list])
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ module InstanceOverrides
24
+ def send_async(*args)
25
+ Fluere.assert_stubbed
26
+ self.send(*args)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ module Fluere
2
+ class Config
3
+ class << self
4
+ attr_accessor :domain
5
+ attr_accessor :logger
6
+ attr_accessor :use_forking
7
+ attr_accessor :task_list_prefix
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Fluere
2
+ class StubbedPathOnlyError < RuntimeError
3
+ def initialize
4
+ super("Fluere must be stubbed when executing this code path.")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Fluere
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,42 @@
1
+ module Fluere
2
+ class Worker
3
+ def self.for(klass)
4
+ assert_fluere_class(klass)
5
+ new(klass)
6
+ end
7
+
8
+ def self.assert_fluere_class(klass)
9
+ unless klass.respond_to? :fluere_worker_klass
10
+ raise "must pass class extended with Fluere::Worker or Fluere::Activity"
11
+ end
12
+ end
13
+
14
+ def initialize(klass)
15
+ @klass = klass
16
+ end
17
+
18
+ def aws_flow_worker
19
+ @aws_flow_worker ||= @klass.fluere_worker_klass.new(
20
+ Fluere.swf.client,
21
+ Fluere.domain,
22
+ Fluere.prefixed_task_list(@klass.task_list),
23
+ @klass,
24
+ ) {{
25
+ logger: Fluere::Config.logger,
26
+ use_forking: Fluere::Config.use_forking
27
+ }}
28
+ end
29
+
30
+ def start
31
+ aws_flow_worker.start
32
+ end
33
+
34
+ def run_once
35
+ aws_flow_worker.run_once
36
+ end
37
+
38
+ def register
39
+ aws_flow_worker.register
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,60 @@
1
+ module Fluere
2
+ module Workflow
3
+ def self.extended(base)
4
+ base.extend(AWS::Flow::Workflows)
5
+ base.extend(ClassOverrides)
6
+ base.send(:include, InstanceOverrides)
7
+ Fluere.workflows << base
8
+ end
9
+
10
+ def fluere_worker_klass
11
+ AWS::Flow::WorkflowWorker
12
+ end
13
+
14
+ def start_execution(*args)
15
+ workflow_client.start_execution(*args)
16
+ end
17
+
18
+ def workflow_client
19
+ AWS::Flow.workflow_client(
20
+ Fluere.swf.client,
21
+ Fluere.domain
22
+ ) {{
23
+ from_class: self.name
24
+ }}
25
+ end
26
+
27
+ module ClassOverrides
28
+ def activity_client(name, &block)
29
+ flow_method = "#{name}_flow".to_sym
30
+ super(flow_method, &block)
31
+ define_method(name) do
32
+ if Fluere.stubbed?
33
+ klass = self.class.const_get(block.call[:from_class])
34
+ klass.new
35
+ else
36
+ send(flow_method)
37
+ end
38
+ end
39
+ end
40
+
41
+ def workflow(name, &block)
42
+ super(name) do
43
+ block.call.tap do |workflow_options|
44
+ workflow_options[:task_list] = Fluere.prefixed_task_list(workflow_options[:task_list])
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ module InstanceOverrides
51
+ def wait_for_all(*args)
52
+ if Fluere.stubbed?
53
+ true # pass
54
+ else
55
+ super(*args)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ describe 'Fluere::Activity' do
4
+ it 'implies AWS::Flow::Activities' do
5
+ klass = Class.new
6
+ klass.extend(Fluere::Activity)
7
+ extended_modules = (class << klass; self; end).included_modules
8
+ extended_modules.must_include AWS::Flow::Activities
9
+ end
10
+
11
+ describe 'with a task prefix set' do
12
+ before { Fluere::Config.task_list_prefix = 'testprefix-' }
13
+ after { Fluere::Config.task_list_prefix = nil }
14
+
15
+ it 'prefixes the activity task_list based off the default_task_list' do
16
+ ActivityWithTaskListPrefix = Class.new
17
+ ActivityWithTaskListPrefix.extend(Fluere::Activity)
18
+
19
+ ActivityWithTaskListPrefix.activity(:test_activity) {{ :default_task_list => 'task_list_name' }}
20
+
21
+ test_activity = ActivityWithTaskListPrefix.activities.find { |a| a.name == 'ActivityWithTaskListPrefix.test_activity' }
22
+ test_activity.options.task_list.must_equal 'testprefix-task_list_name'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ describe 'Fluere::Workflow' do
4
+ it 'implies AWS::Flow::Workflows' do
5
+ klass = Class.new
6
+ klass.extend(Fluere::Workflow)
7
+ extended_modules = (class << klass; self; end).included_modules
8
+ extended_modules.must_include AWS::Flow::Workflows
9
+ end
10
+
11
+ describe 'with a task prefix set' do
12
+ before { Fluere::Config.task_list_prefix = 'testprefix-' }
13
+ after { Fluere::Config.task_list_prefix = nil }
14
+
15
+ it 'prefixes the workflow task_list' do
16
+ WorkflowWithTaskListPrefix = Class.new
17
+ WorkflowWithTaskListPrefix.extend(Fluere::Workflow)
18
+
19
+ WorkflowWithTaskListPrefix.workflow(:test_workflow) {{ :task_list => 'task_list_name' }}
20
+
21
+ test_workflow = WorkflowWithTaskListPrefix.workflows.find { |w| w.name == 'WorkflowWithTaskListPrefix.test_workflow' }
22
+ test_workflow.options.task_list.must_equal 'testprefix-task_list_name'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ FLUERE_LIB_DIR = File.expand_path('../lib', File.dirname(__FILE__))
2
+ $LOAD_PATH << FLUERE_LIB_DIR
3
+ require 'fluere'
4
+ gem 'minitest'
5
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluere
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Paul Hinze
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '5.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: aws-flow
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: A an elegant aws-flow adapter
79
+ email:
80
+ - paulh@instructure.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - fluere.gemspec
91
+ - lib/fluere.rb
92
+ - lib/fluere/activity.rb
93
+ - lib/fluere/config.rb
94
+ - lib/fluere/exceptions.rb
95
+ - lib/fluere/version.rb
96
+ - lib/fluere/worker.rb
97
+ - lib/fluere/workflow.rb
98
+ - test/fluere/activity_test.rb
99
+ - test/fluere/workflow_test.rb
100
+ - test/test_helper.rb
101
+ homepage: ''
102
+ licenses:
103
+ - MIT
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ segments:
115
+ - 0
116
+ hash: -3200458554492036828
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ segments:
124
+ - 0
125
+ hash: -3200458554492036828
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 1.8.23
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: A wrapper around aws-flow that makes it easier to work with
132
+ test_files:
133
+ - test/fluere/activity_test.rb
134
+ - test/fluere/workflow_test.rb
135
+ - test/test_helper.rb