jflow 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -2
- data/README.md +4 -2
- data/bin/jflow_worker +2 -1
- data/jflow.gemspec +5 -3
- data/lib/jflow.rb +8 -9
- data/lib/jflow/activity/definition.rb +83 -0
- data/lib/jflow/activity/map.rb +21 -0
- data/lib/jflow/activity/mixin.rb +20 -0
- data/lib/jflow/activity/task.rb +77 -0
- data/lib/jflow/activity/worker.rb +60 -0
- data/lib/jflow/configuration.rb +5 -4
- data/lib/jflow/version.rb +1 -1
- metadata +47 -31
- data/lib/jflow/activity.rb +0 -81
- data/lib/jflow/activity_mixin.rb +0 -18
- data/lib/jflow/activity_worker.rb +0 -81
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c19f0cda04bce68e814c8a80b8c1e12373cfd5d
|
4
|
+
data.tar.gz: 3e5d33715df6f02f4b5dd89d1a80f9723df53c2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79c03d1f96f1b1f6993ae9b6aaa0a58de9c9933dcf6e98fda164a54d1e5397c5ebf1421218a4e1d97a833005f6639b63f1ab4a39f09c6cde58d07cfd84d170b2
|
7
|
+
data.tar.gz: 7f4ac32fdce779941b00b9a3ec316d2638b026109d98ef65287a517f13cae4ef9e0b8fe3043f0086a844693131f997b2feedf525cb6c4b52df8d49028d5b051a
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Jflow
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/djpate/jflow.svg?branch=master)](https://travis-ci.org/djpate/jflow)
|
4
|
+
|
3
5
|
JFlow is a gem that aims to let you start SWF flow activity workers for JRuby.
|
4
6
|
|
5
7
|
The official framework uses Forking and thus not compatible with the JVM. This aims to give an alternative for Jruby.
|
@@ -28,7 +30,7 @@ Or install it yourself as:
|
|
28
30
|
|
29
31
|
```ruby
|
30
32
|
Class FooActivity
|
31
|
-
include JFlow::
|
33
|
+
include JFlow::Activity::Mixin
|
32
34
|
|
33
35
|
activity "policy_scan.run" do
|
34
36
|
{
|
@@ -76,5 +78,5 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
76
78
|
|
77
79
|
## Contributing
|
78
80
|
|
79
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
81
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/djpate/jflow.
|
80
82
|
|
data/bin/jflow_worker
CHANGED
@@ -22,6 +22,7 @@ raise "configuration is invalid! #{validator.errors}" unless validator.valid?
|
|
22
22
|
|
23
23
|
JFlow.configure do |c|
|
24
24
|
c.load_paths = configuration["activities_path"]
|
25
|
+
c.swf_client = Aws::SWF::Client.new
|
25
26
|
end
|
26
27
|
|
27
28
|
JFlow.load_activities
|
@@ -32,7 +33,7 @@ configuration["number_of_workers"].times do |i|
|
|
32
33
|
threads << Thread.new do
|
33
34
|
domain = configuration["domain"]
|
34
35
|
tasklist = configuration["tasklist"]
|
35
|
-
JFlow::
|
36
|
+
JFlow::Activity::Worker.new(domain, tasklist)
|
36
37
|
.start!
|
37
38
|
end
|
38
39
|
end
|
data/jflow.gemspec
CHANGED
@@ -26,11 +26,13 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
|
+
spec.add_dependency "slop", "~> 4"
|
30
|
+
|
29
31
|
spec.add_development_dependency "bundler", "~> 1.10"
|
30
32
|
spec.add_development_dependency "rake", "~> 10.0"
|
31
33
|
spec.add_development_dependency "rspec"
|
34
|
+
spec.add_development_dependency "simplecov"
|
35
|
+
spec.add_development_dependency "hash_validator"
|
36
|
+
spec.add_development_dependency "aws-sdk", "~> 2"
|
32
37
|
|
33
|
-
spec.add_dependency "aws-sdk", "~> 2"
|
34
|
-
spec.add_dependency "hash_validator"
|
35
|
-
spec.add_dependency "slop", "~> 4"
|
36
38
|
end
|
data/lib/jflow.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
-
require "jflow/version"
|
2
|
-
require "jflow/activity.rb"
|
3
|
-
require "jflow/activity_mixin.rb"
|
4
|
-
require "jflow/activity_worker.rb"
|
5
|
-
require "jflow/configuration.rb"
|
6
1
|
require "yaml"
|
7
2
|
require "json"
|
8
3
|
require "hash_validator"
|
9
4
|
require 'aws-sdk'
|
5
|
+
require 'logger'
|
6
|
+
require "jflow/version"
|
7
|
+
require "jflow/configuration.rb"
|
8
|
+
require "jflow/activity/definition.rb"
|
9
|
+
require "jflow/activity/mixin.rb"
|
10
|
+
require "jflow/activity/task.rb"
|
11
|
+
require "jflow/activity/map.rb"
|
12
|
+
require "jflow/activity/worker.rb"
|
10
13
|
|
11
14
|
module JFlow
|
12
15
|
class << self
|
@@ -17,10 +20,6 @@ module JFlow
|
|
17
20
|
@configuration ||= Configuration.new
|
18
21
|
end
|
19
22
|
|
20
|
-
def self.reset
|
21
|
-
@configuration = Configuration.new
|
22
|
-
end
|
23
|
-
|
24
23
|
def self.configure
|
25
24
|
yield(configuration)
|
26
25
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module JFlow
|
2
|
+
module Activity
|
3
|
+
class Definition
|
4
|
+
|
5
|
+
DEFAULT_OPTIONS = {}
|
6
|
+
|
7
|
+
OPTIONS_VALIDATOR = {
|
8
|
+
:version => "string",
|
9
|
+
:domain => "string",
|
10
|
+
:name => "string",
|
11
|
+
:default_task_list => {
|
12
|
+
:name => "string"
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
attr_reader :options, :klass
|
17
|
+
|
18
|
+
# Possible options are :
|
19
|
+
# domain: "DomainName", # required
|
20
|
+
# name: "Name", # required
|
21
|
+
# version: "Version", # required
|
22
|
+
# description: "Description",
|
23
|
+
# default_task_start_to_close_timeout: "DurationInSecondsOptional",
|
24
|
+
# default_task_heartbeat_timeout: "DurationInSecondsOptional",
|
25
|
+
# default_task_list: {
|
26
|
+
# name: "Name", # required
|
27
|
+
# },
|
28
|
+
# default_task_priority: "TaskPriority",
|
29
|
+
# default_task_schedule_to_start_timeout: "DurationInSecondsOptional",
|
30
|
+
# default_task_schedule_to_close_timeout: "DurationInSecondsOptional",
|
31
|
+
def initialize(klass, options = {})
|
32
|
+
@klass = klass
|
33
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
34
|
+
@options[:name] = name
|
35
|
+
validate_activity!
|
36
|
+
register_activity unless registered?
|
37
|
+
add_to_activity_mapping
|
38
|
+
end
|
39
|
+
|
40
|
+
def register_activity
|
41
|
+
JFlow.configuration.swf_client.register_activity_type(options)
|
42
|
+
JFlow.configuration.logger.info "Activity #{name} was registered successfuly"
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_to_activity_mapping
|
46
|
+
JFlow.configuration.activity_map.add_activity(name, options[:version], klass, options)
|
47
|
+
end
|
48
|
+
|
49
|
+
def name
|
50
|
+
@options[:name] || klass.name.to_s.split('::').last.scan(/[A-Z][a-z]*/).join("_").downcase
|
51
|
+
end
|
52
|
+
|
53
|
+
def version
|
54
|
+
@options[:version]
|
55
|
+
end
|
56
|
+
|
57
|
+
def registered?
|
58
|
+
response = JFlow.configuration.swf_client.list_activity_types({
|
59
|
+
domain: options[:domain],
|
60
|
+
name: name,
|
61
|
+
registration_status: "REGISTERED"
|
62
|
+
})
|
63
|
+
|
64
|
+
response.type_infos.each do |type_info|
|
65
|
+
if type_info.activity_type.name == name && type_info.activity_type.version == version
|
66
|
+
JFlow.configuration.logger.info "Activity #{name} #{version} is already registered"
|
67
|
+
return true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
return false
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def validate_activity!
|
77
|
+
validator = HashValidator.validate(@options, OPTIONS_VALIDATOR)
|
78
|
+
raise "Activity #{options[:name]}definition is invalid! #{validator.errors}" unless validator.valid?
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module JFlow
|
2
|
+
module Activity
|
3
|
+
class Map
|
4
|
+
def initialize
|
5
|
+
@map = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def add_activity(name, version, klass, options)
|
9
|
+
@map ||= {}
|
10
|
+
@map[name] ||= {}
|
11
|
+
@map[name][version] = {:class => klass, :options => options}
|
12
|
+
end
|
13
|
+
|
14
|
+
def klass_for(name, version)
|
15
|
+
return nil if !@map.has_key?(name) || !@map[name][version]
|
16
|
+
@map[name][version][:class]
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module JFlow
|
2
|
+
module Activity
|
3
|
+
module Mixin
|
4
|
+
|
5
|
+
def self.included base
|
6
|
+
base.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def activity(name = nil)
|
11
|
+
options = {}
|
12
|
+
options = yield if block_given?
|
13
|
+
options[:name] = name
|
14
|
+
JFlow.configuration.logger.debug "loading #{name}"
|
15
|
+
JFlow::Activity::Definition.new(self, options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module JFlow
|
2
|
+
module Activity
|
3
|
+
class Task
|
4
|
+
|
5
|
+
attr_reader :task
|
6
|
+
|
7
|
+
def initialize(task)
|
8
|
+
@task = task
|
9
|
+
end
|
10
|
+
|
11
|
+
def input
|
12
|
+
YAML.load(task.input)
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def name
|
17
|
+
task.activity_type.name
|
18
|
+
end
|
19
|
+
|
20
|
+
def version
|
21
|
+
task.activity_type.version
|
22
|
+
end
|
23
|
+
|
24
|
+
def token
|
25
|
+
task.token
|
26
|
+
end
|
27
|
+
|
28
|
+
def klass
|
29
|
+
@klass_value ||= JFlow.configuration.activity_map.klass_for(name,version)
|
30
|
+
raise "Could not find code to run for given activity" unless @klass_value
|
31
|
+
@klass_value
|
32
|
+
end
|
33
|
+
|
34
|
+
def method
|
35
|
+
if name.split('.').size > 1
|
36
|
+
method = name.split('.').last
|
37
|
+
else
|
38
|
+
method = "process"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def run!
|
43
|
+
log "Started #{klass}##{method} with #{input}"
|
44
|
+
result = klass.new.send(method, input) || "done"
|
45
|
+
log "Result is #{result.class} #{result}"
|
46
|
+
completed!(result)
|
47
|
+
end
|
48
|
+
|
49
|
+
def completed!(result)
|
50
|
+
swf_client.respond_activity_task_completed({
|
51
|
+
task_token: token,
|
52
|
+
result: result,
|
53
|
+
})
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def failed!(exception)
|
58
|
+
swf_client.respond_activity_task_failed({
|
59
|
+
task_token: token,
|
60
|
+
reason: exception.message,
|
61
|
+
details: exception.backtrace.join("\n"),
|
62
|
+
})
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def swf_client
|
68
|
+
JFlow.configuration
|
69
|
+
.swf_client
|
70
|
+
end
|
71
|
+
|
72
|
+
def log(str)
|
73
|
+
JFlow.configuration.logger.info "[#{Thread.current.object_id}] #{str}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module JFlow
|
2
|
+
module Activity
|
3
|
+
class Worker
|
4
|
+
|
5
|
+
attr_reader :domain, :tasklist
|
6
|
+
|
7
|
+
def initialize(domain, tasklist)
|
8
|
+
@domain = domain
|
9
|
+
@tasklist = tasklist
|
10
|
+
end
|
11
|
+
|
12
|
+
def start!
|
13
|
+
loop do
|
14
|
+
log "Polling for task on #{domain} - #{tasklist}"
|
15
|
+
poll
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def poll
|
22
|
+
response = JFlow.configuration.swf_client.poll_for_activity_task(poll_params)
|
23
|
+
if response.task_token
|
24
|
+
process_task(response)
|
25
|
+
else
|
26
|
+
log "Got no task"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def process_task(response)
|
31
|
+
log "Got task #{response.task_token}"
|
32
|
+
task = ActivityTask.new(response)
|
33
|
+
begin
|
34
|
+
task.run!
|
35
|
+
rescue => exception
|
36
|
+
task.failed!(e)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def identity
|
41
|
+
@identity ||= "#{`hostname`.chomp}-#{Thread.current.object_id}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def log(str)
|
45
|
+
JFlow.configuration.logger.info "[#{Thread.current.object_id}] #{str}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def poll_params
|
49
|
+
{
|
50
|
+
domain: domain,
|
51
|
+
task_list: {
|
52
|
+
name: tasklist,
|
53
|
+
},
|
54
|
+
identity: identity,
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/jflow/configuration.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module JFlow
|
2
2
|
class Configuration
|
3
3
|
|
4
|
-
attr_accessor :swf_client, :load_paths, :logger
|
4
|
+
attr_accessor :swf_client, :load_paths, :logger, :activity_map
|
5
5
|
|
6
6
|
def initialize
|
7
|
-
@swf_client
|
8
|
-
@load_paths
|
9
|
-
@logger
|
7
|
+
@swf_client = nil
|
8
|
+
@load_paths = []
|
9
|
+
@logger = Logger.new(STDOUT)
|
10
|
+
@activity_map = JFlow::Activity::Map.new
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
data/lib/jflow/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christophe Verbinnen
|
@@ -10,16 +10,30 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2016-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: slop
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4'
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - "~>"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '4'
|
25
|
+
prerelease: false
|
26
|
+
type: :runtime
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
version_requirements: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
|
-
- - ~>
|
31
|
+
- - "~>"
|
18
32
|
- !ruby/object:Gem::Version
|
19
33
|
version: '1.10'
|
20
34
|
requirement: !ruby/object:Gem::Requirement
|
21
35
|
requirements:
|
22
|
-
- - ~>
|
36
|
+
- - "~>"
|
23
37
|
- !ruby/object:Gem::Version
|
24
38
|
version: '1.10'
|
25
39
|
prerelease: false
|
@@ -28,12 +42,12 @@ dependencies:
|
|
28
42
|
name: rake
|
29
43
|
version_requirements: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - ~>
|
45
|
+
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '10.0'
|
34
48
|
requirement: !ruby/object:Gem::Requirement
|
35
49
|
requirements:
|
36
|
-
- - ~>
|
50
|
+
- - "~>"
|
37
51
|
- !ruby/object:Gem::Version
|
38
52
|
version: '10.0'
|
39
53
|
prerelease: false
|
@@ -42,58 +56,58 @@ dependencies:
|
|
42
56
|
name: rspec
|
43
57
|
version_requirements: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- -
|
59
|
+
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
61
|
version: '0'
|
48
62
|
requirement: !ruby/object:Gem::Requirement
|
49
63
|
requirements:
|
50
|
-
- -
|
64
|
+
- - ">="
|
51
65
|
- !ruby/object:Gem::Version
|
52
66
|
version: '0'
|
53
67
|
prerelease: false
|
54
68
|
type: :development
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: simplecov
|
57
71
|
version_requirements: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- -
|
73
|
+
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '0'
|
62
76
|
requirement: !ruby/object:Gem::Requirement
|
63
77
|
requirements:
|
64
|
-
- -
|
78
|
+
- - ">="
|
65
79
|
- !ruby/object:Gem::Version
|
66
|
-
version: '
|
80
|
+
version: '0'
|
67
81
|
prerelease: false
|
68
|
-
type: :
|
82
|
+
type: :development
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: hash_validator
|
71
85
|
version_requirements: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- -
|
87
|
+
- - ">="
|
74
88
|
- !ruby/object:Gem::Version
|
75
89
|
version: '0'
|
76
90
|
requirement: !ruby/object:Gem::Requirement
|
77
91
|
requirements:
|
78
|
-
- -
|
92
|
+
- - ">="
|
79
93
|
- !ruby/object:Gem::Version
|
80
94
|
version: '0'
|
81
95
|
prerelease: false
|
82
|
-
type: :
|
96
|
+
type: :development
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: aws-sdk
|
85
99
|
version_requirements: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
|
-
- - ~>
|
101
|
+
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
103
|
+
version: '2'
|
90
104
|
requirement: !ruby/object:Gem::Requirement
|
91
105
|
requirements:
|
92
|
-
- - ~>
|
106
|
+
- - "~>"
|
93
107
|
- !ruby/object:Gem::Version
|
94
|
-
version: '
|
108
|
+
version: '2'
|
95
109
|
prerelease: false
|
96
|
-
type: :
|
110
|
+
type: :development
|
97
111
|
description: you know, for flow
|
98
112
|
email:
|
99
113
|
- christophe.verbinnen@lookout.com
|
@@ -104,9 +118,9 @@ executables:
|
|
104
118
|
extensions: []
|
105
119
|
extra_rdoc_files: []
|
106
120
|
files:
|
107
|
-
- .gitignore
|
108
|
-
- .rspec
|
109
|
-
- .travis.yml
|
121
|
+
- ".gitignore"
|
122
|
+
- ".rspec"
|
123
|
+
- ".travis.yml"
|
110
124
|
- Gemfile
|
111
125
|
- README.md
|
112
126
|
- Rakefile
|
@@ -115,9 +129,11 @@ files:
|
|
115
129
|
- bin/setup
|
116
130
|
- jflow.gemspec
|
117
131
|
- lib/jflow.rb
|
118
|
-
- lib/jflow/activity.rb
|
119
|
-
- lib/jflow/
|
120
|
-
- lib/jflow/
|
132
|
+
- lib/jflow/activity/definition.rb
|
133
|
+
- lib/jflow/activity/map.rb
|
134
|
+
- lib/jflow/activity/mixin.rb
|
135
|
+
- lib/jflow/activity/task.rb
|
136
|
+
- lib/jflow/activity/worker.rb
|
121
137
|
- lib/jflow/configuration.rb
|
122
138
|
- lib/jflow/version.rb
|
123
139
|
homepage: https://github.com/djpate/jflow
|
@@ -130,17 +146,17 @@ require_paths:
|
|
130
146
|
- lib
|
131
147
|
required_ruby_version: !ruby/object:Gem::Requirement
|
132
148
|
requirements:
|
133
|
-
- -
|
149
|
+
- - ">="
|
134
150
|
- !ruby/object:Gem::Version
|
135
151
|
version: '0'
|
136
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
153
|
requirements:
|
138
|
-
- -
|
154
|
+
- - ">="
|
139
155
|
- !ruby/object:Gem::Version
|
140
156
|
version: '0'
|
141
157
|
requirements: []
|
142
158
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.4.
|
159
|
+
rubygems_version: 2.4.8
|
144
160
|
signing_key:
|
145
161
|
specification_version: 4
|
146
162
|
summary: SWF Flow framework for jRuby
|
data/lib/jflow/activity.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
module JFlow
|
2
|
-
class Activity
|
3
|
-
|
4
|
-
DEFAULT_OPTIONS = {}
|
5
|
-
|
6
|
-
OPTIONS_VALIDATOR = {
|
7
|
-
:version => "string",
|
8
|
-
:domain => "string",
|
9
|
-
:name => "string",
|
10
|
-
:default_task_list => {
|
11
|
-
:name => "string"
|
12
|
-
}
|
13
|
-
}
|
14
|
-
|
15
|
-
attr_reader :options, :klass
|
16
|
-
|
17
|
-
# Possible options are :
|
18
|
-
# domain: "DomainName", # required
|
19
|
-
# name: "Name", # required
|
20
|
-
# version: "Version", # required
|
21
|
-
# description: "Description",
|
22
|
-
# default_task_start_to_close_timeout: "DurationInSecondsOptional",
|
23
|
-
# default_task_heartbeat_timeout: "DurationInSecondsOptional",
|
24
|
-
# default_task_list: {
|
25
|
-
# name: "Name", # required
|
26
|
-
# },
|
27
|
-
# default_task_priority: "TaskPriority",
|
28
|
-
# default_task_schedule_to_start_timeout: "DurationInSecondsOptional",
|
29
|
-
# default_task_schedule_to_close_timeout: "DurationInSecondsOptional",
|
30
|
-
def initialize(klass, options = {})
|
31
|
-
@klass = klass
|
32
|
-
@options = DEFAULT_OPTIONS.merge(options)
|
33
|
-
@options[:name] = name
|
34
|
-
validate_activity!
|
35
|
-
register_activity unless registered?
|
36
|
-
add_to_activity_mapping
|
37
|
-
end
|
38
|
-
|
39
|
-
def register_activity
|
40
|
-
JFlow.configuration.swf_client.register_activity_type(options)
|
41
|
-
JFlow.configuration.logger.info "Activity #{name} was registered successfuly"
|
42
|
-
end
|
43
|
-
|
44
|
-
def add_to_activity_mapping
|
45
|
-
$activity_map ||= {}
|
46
|
-
$activity_map[name] ||= {}
|
47
|
-
$activity_map[name][options[:version]] = {:class => klass, :options => options}
|
48
|
-
end
|
49
|
-
|
50
|
-
def name
|
51
|
-
@options[:name] || klass.name.to_s.split('::').last.scan(/[A-Z][a-z]*/).join("_").downcase
|
52
|
-
end
|
53
|
-
|
54
|
-
def version
|
55
|
-
@options[:version]
|
56
|
-
end
|
57
|
-
|
58
|
-
def validate_activity!
|
59
|
-
validator = HashValidator.validate(@options, OPTIONS_VALIDATOR)
|
60
|
-
raise "Activity #{options[:name]}definition is invalid! #{validator.errors}" unless validator.valid?
|
61
|
-
end
|
62
|
-
|
63
|
-
def registered?
|
64
|
-
response = JFlow.configuration.swf_client.list_activity_types({
|
65
|
-
domain: options[:domain],
|
66
|
-
name: name,
|
67
|
-
registration_status: "REGISTERED"
|
68
|
-
})
|
69
|
-
|
70
|
-
response.type_infos.each do |type_info|
|
71
|
-
if type_info.activity_type.name == name && type_info.activity_type.version == version
|
72
|
-
JFlow.configuration.logger.info "Activity #{name} #{version} is already registered"
|
73
|
-
return true
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
return false
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
data/lib/jflow/activity_mixin.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module JFlow
|
2
|
-
module ActivityMixin
|
3
|
-
|
4
|
-
def self.included base
|
5
|
-
base.extend ClassMethods
|
6
|
-
end
|
7
|
-
|
8
|
-
module ClassMethods
|
9
|
-
def activity(name = nil)
|
10
|
-
options = {}
|
11
|
-
options = yield if block_given?
|
12
|
-
options[:name] = name
|
13
|
-
JFlow.configuration.logger.debug "loading #{name}"
|
14
|
-
JFlow::Activity.new(self, options)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
module JFlow
|
2
|
-
class ActivityWorker
|
3
|
-
|
4
|
-
attr_reader :domain, :tasklist
|
5
|
-
|
6
|
-
def initialize(domain, tasklist)
|
7
|
-
@domain = domain
|
8
|
-
@tasklist = tasklist
|
9
|
-
end
|
10
|
-
|
11
|
-
def start!
|
12
|
-
loop do
|
13
|
-
log "Polling for task on #{domain} - #{tasklist}"
|
14
|
-
poll
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def poll
|
21
|
-
response = JFlow.configuration.swf_client.poll_for_activity_task(poll_params)
|
22
|
-
if response.task_token
|
23
|
-
process_task(response)
|
24
|
-
else
|
25
|
-
log "Got no task"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def process_task(response)
|
30
|
-
log "Got task #{response.task_token}"
|
31
|
-
|
32
|
-
klass = class_for_activity(response.activity_type)
|
33
|
-
raise "Could not find code to run for given activity" unless klass
|
34
|
-
|
35
|
-
begin
|
36
|
-
JFlow.configuration.logger.debug "Started #{klass}#process with #{YAML.load(response.input)}"
|
37
|
-
if response.activity_type.name.split('.').size > 1
|
38
|
-
method = response.activity_type.name.split('.').last
|
39
|
-
else
|
40
|
-
method = "process"
|
41
|
-
end
|
42
|
-
result = klass.new.send(method, YAML.load(response.input)) || true
|
43
|
-
JFlow.configuration.logger.debug "Done #{klass}##{method}"
|
44
|
-
JFlow.configuration.swf_client.respond_activity_task_completed({
|
45
|
-
task_token: response.task_token,
|
46
|
-
result: result,
|
47
|
-
})
|
48
|
-
rescue => e
|
49
|
-
JFlow.configuration.swf_client.respond_activity_task_failed({
|
50
|
-
task_token: response.task_token,
|
51
|
-
reason: e.message,
|
52
|
-
details: e.backtrace.join("\n"),
|
53
|
-
})
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
def identity
|
59
|
-
@identity ||= "#{`hostname`.chomp}-#{Thread.current.object_id}"
|
60
|
-
end
|
61
|
-
|
62
|
-
def log(str)
|
63
|
-
JFlow.configuration.logger.info "[#{Thread.current.object_id}] #{str}"
|
64
|
-
end
|
65
|
-
|
66
|
-
def poll_params
|
67
|
-
{
|
68
|
-
domain: domain,
|
69
|
-
task_list: {
|
70
|
-
name: tasklist,
|
71
|
-
},
|
72
|
-
identity: identity,
|
73
|
-
}
|
74
|
-
end
|
75
|
-
|
76
|
-
def class_for_activity(activity_type)
|
77
|
-
$activity_map[activity_type.name][activity_type.version][:class]
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|