tumugi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,101 @@
1
+ require 'tumugi/task'
2
+
3
+ module Tumugi
4
+ class TaskDefinition
5
+ include Tumugi::Helper
6
+
7
+ def self.define(id, opts={}, &block)
8
+ td = Tumugi::TaskDefinition.new(id, opts)
9
+ td.instance_eval(&block)
10
+ Tumugi.application.add_task(id, td)
11
+ td
12
+ end
13
+
14
+ attr_reader :id, :opts
15
+
16
+ def initialize(id, opts={})
17
+ @id = id
18
+ @opts = { type: Tumugi::Task }.merge(opts)
19
+ end
20
+
21
+ def instance
22
+ @task ||= create_task
23
+ end
24
+
25
+ def requires(tasks)
26
+ @required_tasks = tasks
27
+ end
28
+
29
+ def output(outputs=[], &block)
30
+ @outputs ||= (block || outputs)
31
+ end
32
+
33
+ def run(&block)
34
+ @run = block
35
+ end
36
+
37
+ def output_eval(task)
38
+ @out ||= @outputs.is_a?(Proc) ? @outputs.call(task) : @outputs
39
+ end
40
+
41
+ def required_tasks
42
+ @required_tasks
43
+ end
44
+
45
+ def run_block(task)
46
+ @run.call(task)
47
+ end
48
+
49
+ private
50
+
51
+ def create_task
52
+ task = define_task.new
53
+ task.id = @id
54
+ task
55
+ end
56
+
57
+ def define_task
58
+ task_class = Class.new(@opts[:type])
59
+ define_requires_method(task_class)
60
+ define_output_method(task_class)
61
+ define_run_method(task_class)
62
+ task_class
63
+ end
64
+
65
+ def define_requires_method(task_class)
66
+ td = self
67
+ task_class.class_eval do
68
+ define_method(:requires) do
69
+ reqs = td.required_tasks
70
+ if reqs.nil?
71
+ []
72
+ elsif reqs.is_a?(Array)
73
+ reqs.map { |t| Tumugi.application.find_task(t) }
74
+ elsif reqs.is_a?(Hash)
75
+ Hash[reqs.map { |k, t| [k, Tumugi.application.find_task(t)] }]
76
+ else
77
+ Tumugi.application.find_task(reqs)
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ def define_output_method(task_class)
84
+ td = self
85
+ task_class.class_eval do
86
+ define_method(:output) do
87
+ td.output_eval(self)
88
+ end
89
+ end unless @outputs.nil?
90
+ end
91
+
92
+ def define_run_method(task_class)
93
+ td = self
94
+ task_class.class_eval do
95
+ define_method(:run) do
96
+ td.run_block(self)
97
+ end
98
+ end unless @run.nil?
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,23 @@
1
+ require 'tumugi/application'
2
+ require 'tumugi/config'
3
+ require 'tumugi/logger'
4
+
5
+ module Tumugi
6
+ class << self
7
+ def application
8
+ @application ||= Tumugi::Application.new
9
+ end
10
+
11
+ def logger
12
+ @logger ||= Tumugi::Logger.new
13
+ end
14
+
15
+ def config
16
+ @config ||= Tumugi::Config.new
17
+ if block_given?
18
+ yield @config
19
+ end
20
+ @config
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Tumugi
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tumugi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'tumugi'
8
+ spec.version = Tumugi::VERSION
9
+ spec.authors = ['Kazuyuki Honda']
10
+ spec.email = ['hakobera@gmail.com']
11
+
12
+ spec.summary = 'Tumugi is a library to build, run and manage complex workflows. Tumugi enables you to define workflows as a ruby code.'
13
+ spec.homepage = 'https://github.com/tumugi/tumugi'
14
+ spec.license = 'Apache License Version 2.0'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'activesupport', '~> 4.2'
22
+ spec.add_runtime_dependency 'gviz', '~> 0.3.5'
23
+ spec.add_runtime_dependency 'thor', '~> 0.19.1'
24
+ spec.add_runtime_dependency 'parallel', '~> 1.8.0'
25
+ spec.add_runtime_dependency 'retriable', '~> 2.1'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.11'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'test-unit', '~> 3.1'
30
+ spec.add_development_dependency 'test-unit-rr'
31
+ spec.add_development_dependency 'coveralls'
32
+ end
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tumugi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kazuyuki Honda
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gviz
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.19.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.19.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: parallel
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: retriable
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.11'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.11'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: test-unit
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.1'
125
+ - !ruby/object:Gem::Dependency
126
+ name: test-unit-rr
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: coveralls
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description:
154
+ email:
155
+ - hakobera@gmail.com
156
+ executables:
157
+ - tumugi
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".gitignore"
162
+ - ".travis.yml"
163
+ - Gemfile
164
+ - LICENSE
165
+ - README.md
166
+ - Rakefile
167
+ - bin/console
168
+ - bin/setup
169
+ - examples/concurrent_task_run.rb
170
+ - examples/data_pipeline.rb
171
+ - examples/simple.rb
172
+ - examples/target.rb
173
+ - examples/task_inheritance.rb
174
+ - exe/tumugi
175
+ - lib/tumugi.rb
176
+ - lib/tumugi/application.rb
177
+ - lib/tumugi/cli.rb
178
+ - lib/tumugi/command/run.rb
179
+ - lib/tumugi/command/show.rb
180
+ - lib/tumugi/config.rb
181
+ - lib/tumugi/dag.rb
182
+ - lib/tumugi/dsl.rb
183
+ - lib/tumugi/helper.rb
184
+ - lib/tumugi/logger.rb
185
+ - lib/tumugi/target/base.rb
186
+ - lib/tumugi/target/file_target.rb
187
+ - lib/tumugi/task.rb
188
+ - lib/tumugi/task_definition.rb
189
+ - lib/tumugi/tumugi_module.rb
190
+ - lib/tumugi/version.rb
191
+ - tumugi.gemspec
192
+ homepage: https://github.com/tumugi/tumugi
193
+ licenses:
194
+ - Apache License Version 2.0
195
+ metadata: {}
196
+ post_install_message:
197
+ rdoc_options: []
198
+ require_paths:
199
+ - lib
200
+ required_ruby_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ required_rubygems_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ requirements: []
211
+ rubyforge_project:
212
+ rubygems_version: 2.5.1
213
+ signing_key:
214
+ specification_version: 4
215
+ summary: Tumugi is a library to build, run and manage complex workflows. Tumugi enables
216
+ you to define workflows as a ruby code.
217
+ test_files: []