rockflow 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/README.md +101 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/rockflow/flow.rb +42 -0
- data/lib/rockflow/step.rb +48 -0
- data/lib/rockflow/version.rb +3 -0
- data/lib/rockflow.rb +6 -0
- data/rockflow.gemspec +27 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b682fb3b2338fa9ebb7b1846778b86e9736ef499
|
4
|
+
data.tar.gz: 9a80879bc9d000c23fd1a2822128b8565dce1b68
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1fdf33c5dd77e323941b3b9182b4aad95f409af4cded49750de5432d5f53ac68fdfa9700b5bed97dd0dc6495509dc11f03a53b0c14e27c6fdcc8d11664201147
|
7
|
+
data.tar.gz: 09d19df5250fcc4f809d118cbdc6e19c514ec9761e66bb595c6efc1006fa71e8ceef3618304c5fda1d9eb0e92c0d90a61ff1f64d453d77c0cbef111dbbf3469c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# Rockflow
|
2
|
+
|
3
|
+
What is rockflow? Well with rockflow you are able to define workflows (yes even parallel workflows) by writing simple small steps and aggregating them in your flow (the bigger picture... you know)
|
4
|
+
|
5
|
+
Let's start the tour!
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rockflow'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rockflow
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
To write your own flow you need two ingredients: the **flow** and your **steps** lets start by looking at the flow.
|
26
|
+
|
27
|
+
##### Flow
|
28
|
+
```ruby
|
29
|
+
# app/workflows/awesome_flow.rb
|
30
|
+
class AwesomeFlow < Rockflow::Flow
|
31
|
+
def setup
|
32
|
+
rock RockStep1
|
33
|
+
rock RockStep2
|
34
|
+
rock RockStep3, after: [RockStep1, RockStep2]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
```
|
38
|
+
Easy right? Notice that **RockStep1** and **RockStep2** will be executed parallel (so beware of thread safety and stuff). **RockStep3** will only execute if **RockStep1** and **RockStep2** are finished.
|
39
|
+
Here is a picture.
|
40
|
+
|
41
|
+
## [![](http://i.imgur.com/7BrU2kT.png)](https://qurasoft.de)
|
42
|
+
##### Steps
|
43
|
+
Look at my steps ... my steps are amazing...
|
44
|
+
```ruby
|
45
|
+
# app/steps/rock_step1.rb
|
46
|
+
class RockStep1 < Rockflow::Step
|
47
|
+
def it_up
|
48
|
+
puts "Iam RockStep1 and i am adding something to the payload"
|
49
|
+
add_payload :a, 2
|
50
|
+
end
|
51
|
+
end
|
52
|
+
```
|
53
|
+
```ruby
|
54
|
+
# app/steps/rock_step2.rb
|
55
|
+
class RockStep2 < Rockflow::Step
|
56
|
+
def it_up
|
57
|
+
puts "Iam RockStep2 and i am adding something to the payload"
|
58
|
+
add_payload :b, 2
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
# app/steps/rock_step3.rb
|
65
|
+
class RockStep3 < Rockflow::Step
|
66
|
+
def it_up
|
67
|
+
puts "Iam RockStep3 and i am aggregating something from the payload"
|
68
|
+
result = payload[:a] + payload[:b] + payload[:c]
|
69
|
+
puts "Result: #{result}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
```
|
73
|
+
So now i have defined my steps and my flow but how can i execute it? Well simple just use it like this:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
flow = AwesomeFlow.new
|
77
|
+
flow.concert! # execute all steps
|
78
|
+
```
|
79
|
+
|
80
|
+
#### Summary
|
81
|
+
Define your flow by inheriting from **RockFlow::Flow**. Inside your defined flow override the setup method and use the **rock** keyword defined by your step class. Available options for the rock method are at the moment:
|
82
|
+
- **after** which takes a StepClass or an array of step classes.
|
83
|
+
|
84
|
+
After that start writing your steps by inheriting from **RockFlow::Step** and overriding the **it_up** method. Inside of your inherited class you can use following methods.
|
85
|
+
|
86
|
+
- add_payload key, value - This method adds data that can be used across your steps inside of your flow
|
87
|
+
- payload - This method gives you the chance to access your whole payload from your flow.
|
88
|
+
|
89
|
+
## Development
|
90
|
+
|
91
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
92
|
+
|
93
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
94
|
+
|
95
|
+
## Contributing
|
96
|
+
|
97
|
+
1. Fork it ( https://github.com/[my-github-username]/rockflow/fork )
|
98
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
99
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
100
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
101
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rockflow"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Rockflow
|
2
|
+
class Flow
|
3
|
+
|
4
|
+
attr_accessor :steps, :payload
|
5
|
+
|
6
|
+
def initialize(payload = {})
|
7
|
+
@steps = []
|
8
|
+
@payload = payload
|
9
|
+
setup
|
10
|
+
end
|
11
|
+
|
12
|
+
def setup
|
13
|
+
end
|
14
|
+
|
15
|
+
def rock(klazz, opts = {})
|
16
|
+
@steps << klazz.new(self, opts)
|
17
|
+
end
|
18
|
+
|
19
|
+
def concert!
|
20
|
+
while !steps_finished?
|
21
|
+
::Parallel.each(next_free_steps, in_threads: 4) do |step|
|
22
|
+
step.it_up
|
23
|
+
step.finish!
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def next_free_steps
|
29
|
+
@steps.select do |step|
|
30
|
+
step.after_dependencies_finished? && !step.finished?
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def steps_finished?
|
35
|
+
@steps.inject(true) do |result, elem|
|
36
|
+
result = result && elem.finished?
|
37
|
+
result
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Rockflow
|
2
|
+
class Step
|
3
|
+
attr_accessor :flow, :status
|
4
|
+
|
5
|
+
def initialize(flow, opts = {})
|
6
|
+
@flow = flow
|
7
|
+
@after_dependencies = []
|
8
|
+
@status = :not_started
|
9
|
+
add_after_dependencies(opts[:after])
|
10
|
+
end
|
11
|
+
|
12
|
+
def it_up
|
13
|
+
end
|
14
|
+
|
15
|
+
def payload
|
16
|
+
@flow.payload
|
17
|
+
end
|
18
|
+
|
19
|
+
def finish!
|
20
|
+
@status = :finished
|
21
|
+
end
|
22
|
+
|
23
|
+
def finished?
|
24
|
+
@status == :finished
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_payload(key, value)
|
28
|
+
@flow.payload[key] = value
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_after_dependencies(deps = [])
|
32
|
+
[deps].flatten.each do |dep|
|
33
|
+
@after_dependencies << dep
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def after_dependencies_finished?
|
38
|
+
@after_dependencies.inject(true) do |result, elem|
|
39
|
+
dependent_steps_running = !(@flow.steps.select do |step|
|
40
|
+
step.class == elem && !step.finished?
|
41
|
+
end.any?)
|
42
|
+
result = result && dependent_steps_running
|
43
|
+
result
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
data/lib/rockflow.rb
ADDED
data/rockflow.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rockflow/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rockflow"
|
8
|
+
spec.version = Rockflow::VERSION
|
9
|
+
spec.authors = ["Erwin Schens"]
|
10
|
+
spec.email = ["erwinschens@uni-koblenz.de"]
|
11
|
+
|
12
|
+
spec.summary = %q{Create workflows the easy way}
|
13
|
+
spec.description = %q{Rockflow allows you to define easy workflows that rock.}
|
14
|
+
spec.homepage = "http://qurasoft.de"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency 'parallel', '~> 1.6.1', '>= 1.6.1'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rockflow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Erwin Schens
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: parallel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.1
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.6.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.6.1
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.6.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.8'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.8'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.3'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.3'
|
75
|
+
description: Rockflow allows you to define easy workflows that rock.
|
76
|
+
email:
|
77
|
+
- erwinschens@uni-koblenz.de
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- ".gitignore"
|
83
|
+
- ".rspec"
|
84
|
+
- Gemfile
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- bin/console
|
88
|
+
- bin/setup
|
89
|
+
- lib/rockflow.rb
|
90
|
+
- lib/rockflow/flow.rb
|
91
|
+
- lib/rockflow/step.rb
|
92
|
+
- lib/rockflow/version.rb
|
93
|
+
- rockflow.gemspec
|
94
|
+
homepage: http://qurasoft.de
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.4.6
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Create workflows the easy way
|
118
|
+
test_files: []
|