rukawa 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +61 -22
- data/lib/rukawa/cli.rb +56 -30
- data/lib/rukawa/dag.rb +2 -2
- data/lib/rukawa/job.rb +3 -2
- data/lib/rukawa/job_net.rb +2 -2
- data/lib/rukawa/version.rb +1 -1
- data/sample/jobs/sample_job.rb +5 -0
- data/sample/variables.json +1 -0
- data/sample/variables.yml +6 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e90c29a3fb28cf675e9c34e2be8a10e642819f19
|
4
|
+
data.tar.gz: f967d48f8faced73d118c7c752e3f1c28cb062fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c98fbb5ebf627f6133337c4d88e88556ce199eec049a65ca610f1faa0c74f932461086cbd0687d18a28fd52378c6cb9d2d4a15522423e113d7c1a90318c5f0a5
|
7
|
+
data.tar.gz: 1c763aa161305e1d6db416be8f8237d40c4f432e9e3b8edefaad3002e179eece6da0bbc118913f1261ba4425e25cbb5ec5d77484ce16a588a6e71291f6489f27
|
data/README.md
CHANGED
@@ -227,6 +227,41 @@ Main usage is manual reentering.
|
|
227
227
|
% dot -Tpng -o SampleJobNet.png SampleJobNet.dot
|
228
228
|
```
|
229
229
|
|
230
|
+
### Use variables
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
class Job < Rukawa::Job
|
234
|
+
def run
|
235
|
+
# access via `variables` method
|
236
|
+
# return freezed Hash object
|
237
|
+
puts variables["var1"]
|
238
|
+
puts variables["var2"]
|
239
|
+
end
|
240
|
+
end
|
241
|
+
```
|
242
|
+
|
243
|
+
```sh
|
244
|
+
% bundle exec rukawa run SampleJobNet --var var1:value1 var2:value2
|
245
|
+
# or
|
246
|
+
% bundle exec rukawa run SampleJobNet --varfile variables.yml
|
247
|
+
# or
|
248
|
+
% bundle exec rukawa run SampleJobNet --varfile variables.json
|
249
|
+
```
|
250
|
+
|
251
|
+
```yml
|
252
|
+
# variables.yml
|
253
|
+
var1: value1
|
254
|
+
var2: value2
|
255
|
+
```
|
256
|
+
|
257
|
+
```javascript
|
258
|
+
// variables.json
|
259
|
+
{
|
260
|
+
"var1": "value1",
|
261
|
+
"var2": "value2"
|
262
|
+
}
|
263
|
+
```
|
264
|
+
|
230
265
|
### Config Example
|
231
266
|
|
232
267
|
```
|
@@ -249,17 +284,19 @@ Usage:
|
|
249
284
|
rukawa run JOB_NET_NAME [JOB_NAME] [JOB_NAME] ...
|
250
285
|
|
251
286
|
Options:
|
252
|
-
|
253
|
-
[--
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
-
|
258
|
-
|
259
|
-
[--stdout], [--no-stdout]
|
260
|
-
|
261
|
-
-
|
262
|
-
|
287
|
+
[--config=CONFIG] # If this options is not set, try to load ./rukawa.rb
|
288
|
+
[--job-dirs=JOB_DIR1 JOB_DIR2] # Load job directories
|
289
|
+
-c, [--concurrency=N] # Default: cpu count
|
290
|
+
--var, [--variables=KEY:VALUE KEY:VALUE]
|
291
|
+
[--varfile=VARFILE] # variable definition file. ex (variables.yml, variables.json)
|
292
|
+
-b, [--batch], [--no-batch] # If batch mode, not display running status
|
293
|
+
-l, [--log=LOG] # Default: ./rukawa.log
|
294
|
+
[--stdout], [--no-stdout] # Output log to stdout
|
295
|
+
[--syslog], [--no-syslog] # Output log to syslog
|
296
|
+
-d, [--dot=DOT] # Output job status by dot format
|
297
|
+
-f, [--format=FORMAT] # Output job status format: png, svg, pdf, ... etc
|
298
|
+
-r, [--refresh-interval=N] # Refresh interval for running status information
|
299
|
+
# Default: 3
|
263
300
|
|
264
301
|
Run jobnet. If JOB_NET is set, resume from JOB_NAME
|
265
302
|
|
@@ -269,17 +306,19 @@ Usage:
|
|
269
306
|
rukawa run_job JOB_NAME [JOB_NAME] ...
|
270
307
|
|
271
308
|
Options:
|
272
|
-
|
273
|
-
[--
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
-
|
278
|
-
|
279
|
-
[--stdout], [--no-stdout]
|
280
|
-
|
281
|
-
-
|
282
|
-
|
309
|
+
[--config=CONFIG] # If this options is not set, try to load ./rukawa.rb
|
310
|
+
[--job-dirs=JOB_DIR1 JOB_DIR2] # Load job directories
|
311
|
+
-c, [--concurrency=N] # Default: cpu count
|
312
|
+
--var, [--variables=KEY:VALUE KEY:VALUE]
|
313
|
+
[--varfile=VARFILE] # variable definition file. ex (variables.yml, variables.json)
|
314
|
+
-b, [--batch], [--no-batch] # If batch mode, not display running status
|
315
|
+
-l, [--log=LOG] # Default: ./rukawa.log
|
316
|
+
[--stdout], [--no-stdout] # Output log to stdout
|
317
|
+
[--syslog], [--no-syslog] # Output log to syslog
|
318
|
+
-d, [--dot=DOT] # Output job status by dot format
|
319
|
+
-f, [--format=FORMAT] # Output job status format: png, svg, pdf, ... etc
|
320
|
+
-r, [--refresh-interval=N] # Refresh interval for running status information
|
321
|
+
# Default: 3
|
283
322
|
|
284
323
|
Run specific jobs.
|
285
324
|
|
data/lib/rukawa/cli.rb
CHANGED
@@ -4,20 +4,29 @@ require 'rukawa/overview'
|
|
4
4
|
|
5
5
|
module Rukawa
|
6
6
|
class Cli < Thor
|
7
|
+
|
8
|
+
def self.base_options
|
9
|
+
method_option :config, type: :string, default: nil, desc: "If this options is not set, try to load ./rukawa.rb"
|
10
|
+
method_option :job_dirs, type: :array, default: [], desc: "Load job directories", banner: "JOB_DIR1 JOB_DIR2"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.run_options
|
14
|
+
method_option :concurrency, aliases: "-c", type: :numeric, default: nil, desc: "Default: cpu count"
|
15
|
+
method_option :variables, aliases: "--var", type: :hash, default: {}, banner: "KEY:VALUE KEY:VALUE"
|
16
|
+
method_option :varfile, type: :string, default: nil, desc: "variable definition file. ex (variables.yml, variables.json)"
|
17
|
+
method_option :batch, aliases: "-b", type: :boolean, default: false, desc: "If batch mode, not display running status"
|
18
|
+
method_option :log, aliases: "-l", type: :string, desc: "Default: ./rukawa.log"
|
19
|
+
method_option :stdout, type: :boolean, default: false, desc: "Output log to stdout"
|
20
|
+
method_option :syslog, type: :boolean, default: false, desc: "Output log to syslog"
|
21
|
+
method_option :dot, aliases: "-d", type: :string, default: nil, desc: "Output job status by dot format"
|
22
|
+
method_option :format, aliases: "-f", type: :string, desc: "Output job status format: png, svg, pdf, ... etc"
|
23
|
+
method_option :refresh_interval, aliases: "-r", type: :numeric, default: 3, desc: "Refresh interval for running status information"
|
24
|
+
end
|
25
|
+
|
7
26
|
desc "run JOB_NET_NAME [JOB_NAME] [JOB_NAME] ...", "Run jobnet. If JOB_NET is set, resume from JOB_NAME"
|
8
27
|
map "run" => "_run"
|
9
|
-
|
10
|
-
|
11
|
-
method_option :variables, type: :hash, default: {}
|
12
|
-
method_option :config, type: :string, default: nil, desc: "If this options is not set, try to load ./rukawa.rb"
|
13
|
-
method_option :job_dirs, type: :array, default: [], desc: "Load job directories"
|
14
|
-
method_option :batch, aliases: "-b", type: :boolean, default: false, desc: "If batch mode, not display running status"
|
15
|
-
method_option :log, aliases: "-l", type: :string, desc: "Default: ./rukawa.log"
|
16
|
-
method_option :stdout, type: :boolean, default: false, desc: "Output log to stdout"
|
17
|
-
method_option :syslog, type: :boolean, default: false, desc: "Output log to syslog"
|
18
|
-
method_option :dot, aliases: "-d", type: :string, default: nil, desc: "Output job status by dot format"
|
19
|
-
method_option :format, aliases: "-f", type: :string, desc: "Output job status format: png, svg, pdf, ... etc"
|
20
|
-
method_option :refresh_interval, aliases: "-r", type: :numeric, default: 3, desc: "Refresh interval for running status information"
|
28
|
+
base_options
|
29
|
+
run_options
|
21
30
|
def _run(job_net_name, *job_name)
|
22
31
|
load_config
|
23
32
|
set_logger
|
@@ -26,7 +35,7 @@ module Rukawa
|
|
26
35
|
|
27
36
|
job_net_class = get_class(job_net_name)
|
28
37
|
job_classes = job_name.map { |name| get_class(name) }
|
29
|
-
job_net = job_net_class.new(nil, *job_classes)
|
38
|
+
job_net = job_net_class.new(nil, variables, *job_classes)
|
30
39
|
result = Runner.run(job_net, options[:batch], options[:refresh_interval])
|
31
40
|
|
32
41
|
if options[:dot]
|
@@ -37,8 +46,7 @@ module Rukawa
|
|
37
46
|
end
|
38
47
|
|
39
48
|
desc "graph JOB_NET_NAME [JOB_NAME] [JOB_NAME] ...", "Output jobnet graph. If JOB_NET is set, simulate resumed job sequence"
|
40
|
-
|
41
|
-
method_option :job_dirs, type: :array, default: []
|
49
|
+
base_options
|
42
50
|
method_option :output, aliases: "-o", type: :string, required: true
|
43
51
|
method_option :format, aliases: "-f", type: :string
|
44
52
|
def graph(job_net_name, *job_name)
|
@@ -47,20 +55,13 @@ module Rukawa
|
|
47
55
|
|
48
56
|
job_net_class = get_class(job_net_name)
|
49
57
|
job_classes = job_name.map { |name| get_class(name) }
|
50
|
-
job_net = job_net_class.new(nil, *job_classes)
|
58
|
+
job_net = job_net_class.new(nil, {}, *job_classes)
|
51
59
|
job_net.output_dot(options[:output], format: options[:format])
|
52
60
|
end
|
53
61
|
|
54
62
|
desc "run_job JOB_NAME [JOB_NAME] ...", "Run specific jobs."
|
55
|
-
|
56
|
-
|
57
|
-
method_option :config, type: :string, default: nil, desc: "If this options is not set, try to load ./rukawa.rb"
|
58
|
-
method_option :job_dirs, type: :array, default: [], desc: "Load job directories"
|
59
|
-
method_option :batch, aliases: "-b", type: :boolean, default: false, desc: "If batch mode, not display running status"
|
60
|
-
method_option :log, aliases: "-l", type: :string, default: "./rukawa.log"
|
61
|
-
method_option :stdout, type: :boolean, default: false, desc: "Output log to stdout"
|
62
|
-
method_option :dot, aliases: "-d", type: :string, default: nil, desc: "Output job status by dot format"
|
63
|
-
method_option :refresh_interval, aliases: "-r", type: :numeric, default: 3, desc: "Refresh interval for running status information"
|
63
|
+
base_options
|
64
|
+
run_options
|
64
65
|
def run_job(*job_name)
|
65
66
|
load_config
|
66
67
|
set_logger
|
@@ -69,7 +70,7 @@ module Rukawa
|
|
69
70
|
|
70
71
|
job_classes = job_name.map { |name| get_class(name) }
|
71
72
|
job_net_class = anonymous_job_net_class(*job_classes)
|
72
|
-
job_net = job_net_class.new(nil)
|
73
|
+
job_net = job_net_class.new(nil, variables)
|
73
74
|
result = Runner.run(job_net, options[:batch], options[:refresh_interval])
|
74
75
|
|
75
76
|
if options[:dot]
|
@@ -80,9 +81,8 @@ module Rukawa
|
|
80
81
|
end
|
81
82
|
|
82
83
|
desc "list", "List JobNet"
|
83
|
-
|
84
|
+
base_options
|
84
85
|
method_option :jobs, aliases: "-j", type: :boolean, desc: "Show jobs", default: false
|
85
|
-
method_option :job_dirs, type: :array, default: [], desc: "Load job directories"
|
86
86
|
def list
|
87
87
|
load_config
|
88
88
|
load_job_definitions
|
@@ -90,14 +90,14 @@ module Rukawa
|
|
90
90
|
end
|
91
91
|
|
92
92
|
desc "list_job", "List Job"
|
93
|
-
|
94
|
-
method_option :job_dirs, type: :array, default: [], desc: "Load job directories"
|
93
|
+
base_options
|
95
94
|
def list_job
|
96
95
|
load_config
|
97
96
|
load_job_definitions
|
98
97
|
Rukawa::Overview.list_job
|
99
98
|
end
|
100
99
|
|
100
|
+
map %w[version -v] => "__print_version"
|
101
101
|
desc "version(-v)", "Print the version"
|
102
102
|
def __print_version
|
103
103
|
puts "rukawa #{Rukawa::VERSION}"
|
@@ -165,5 +165,31 @@ module Rukawa
|
|
165
165
|
define_method(:name) { "AnonymousJobNet" }
|
166
166
|
end
|
167
167
|
end
|
168
|
+
|
169
|
+
def variables
|
170
|
+
if options[:varfile]
|
171
|
+
read_varfile.freeze
|
172
|
+
else
|
173
|
+
options[:variables].freeze
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def read_varfile
|
178
|
+
unless File.exist?(options[:varfile])
|
179
|
+
$stderr.puts("`#{options[:varfile]}` is not found")
|
180
|
+
exit 1
|
181
|
+
end
|
182
|
+
|
183
|
+
extname = File.extname(options[:varfile])
|
184
|
+
if %w(.yml .yaml).include?(extname)
|
185
|
+
require 'yaml'
|
186
|
+
deserializer = ->(data) { YAML.load(data) }
|
187
|
+
elsif %w(.js .json).include?(extname)
|
188
|
+
require 'json'
|
189
|
+
deserializer = ->(data) { JSON.load(data) }
|
190
|
+
end
|
191
|
+
|
192
|
+
deserializer.call(File.read(options[:varfile]))
|
193
|
+
end
|
168
194
|
end
|
169
195
|
end
|
data/lib/rukawa/dag.rb
CHANGED
@@ -14,11 +14,11 @@ module Rukawa
|
|
14
14
|
@edges = Set.new
|
15
15
|
end
|
16
16
|
|
17
|
-
def build(job_net, dependencies)
|
17
|
+
def build(job_net, variables, dependencies)
|
18
18
|
deps = tsortable_hash(dependencies).tsort
|
19
19
|
|
20
20
|
deps.each do |job_class|
|
21
|
-
job = job_class.new(job_net)
|
21
|
+
job = job_class.new(job_net, variables)
|
22
22
|
@nodes << job
|
23
23
|
@jobs << job if job.is_a?(Job)
|
24
24
|
|
data/lib/rukawa/job.rb
CHANGED
@@ -7,7 +7,7 @@ require 'active_support/core_ext/class'
|
|
7
7
|
module Rukawa
|
8
8
|
class Job < AbstractJob
|
9
9
|
attr_accessor :in_comings, :out_goings
|
10
|
-
attr_reader :state, :started_at, :finished_at
|
10
|
+
attr_reader :state, :started_at, :finished_at, :variables
|
11
11
|
|
12
12
|
class_attribute :retryable, :retry_limit, :retry_exception_type, :retry_wait, instance_writer: false
|
13
13
|
class_attribute :dependency_type, instance_writer: false
|
@@ -26,8 +26,9 @@ module Rukawa
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def initialize(parent_job_net)
|
29
|
+
def initialize(parent_job_net, variables)
|
30
30
|
@parent_job_net = parent_job_net
|
31
|
+
@variables = variables
|
31
32
|
@in_comings = Set.new
|
32
33
|
@out_goings = Set.new
|
33
34
|
@retry_count = 0
|
data/lib/rukawa/job_net.rb
CHANGED
@@ -11,10 +11,10 @@ module Rukawa
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def initialize(parent_job_net, *resume_job_classes)
|
14
|
+
def initialize(parent_job_net, variables, *resume_job_classes)
|
15
15
|
@parent_job_net = parent_job_net
|
16
16
|
@dag = Dag.new
|
17
|
-
@dag.build(self, self.class.dependencies)
|
17
|
+
@dag.build(self, variables, self.class.dependencies)
|
18
18
|
@resume_job_classes = resume_job_classes
|
19
19
|
|
20
20
|
unless resume_job_classes.empty?
|
data/lib/rukawa/version.rb
CHANGED
data/sample/jobs/sample_job.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"var1": "var1", "var2": 2, "var3": {"var3-1": 1}}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rukawa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joker1007
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -187,6 +187,8 @@ files:
|
|
187
187
|
- sample/result.dot
|
188
188
|
- sample/result.png
|
189
189
|
- sample/rukawa.rb
|
190
|
+
- sample/variables.json
|
191
|
+
- sample/variables.yml
|
190
192
|
homepage: https://github.com/joker1007/rukawa
|
191
193
|
licenses: []
|
192
194
|
metadata: {}
|