-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1730 from KentFujii/add_ruby_examples_for_generat…
…ing_subtasks add: ruby_examples_for_generating_subtasks
- Loading branch information
Showing
3 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,3 @@ timezone: UTC | |
|
||
+parallel_process: | ||
py>: tasks.generate_subtasks.ParallelProcess.run | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
timezone: UTC | ||
|
||
_export: | ||
rb: | ||
require: tasks/generate_subtasks | ||
|
||
+just_params: | ||
+split: | ||
rb>: JustParams::ParallelProcess.split | ||
+parallel_process: | ||
rb>: JustParams::ParallelProcess.run | ||
|
||
+with_singleton_method: | ||
+split: | ||
rb>: WithSingletonMethod::ParallelProcess.split | ||
+parallel_process: | ||
rb>: WithSingletonMethod::ParallelProcess.run | ||
|
||
+with_instance_method: | ||
+split: | ||
rb>: WithInstanceMethod::ParallelProcess.split | ||
+parallel_process: | ||
rb>: WithInstanceMethod::ParallelProcess.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# add_subtask(params) | ||
module JustParams | ||
class ParallelProcess | ||
def split | ||
Digdag.env.store(task_count: 3) | ||
end | ||
|
||
def run(task_count) | ||
tasks = task_count.times.each_with_object({}) do |i, memo| | ||
memo["+task#{i}"] = { | ||
'rb>': 'JustParams::ParallelProcess.subtask', | ||
index: i | ||
} | ||
end | ||
tasks['_parallel'] = true | ||
Digdag.env.add_subtask(tasks) | ||
end | ||
end | ||
|
||
def subtask(index) | ||
puts("Processing" + index.to_s) | ||
end | ||
end | ||
|
||
# add_subtask(singleton_method_name, params={}) | ||
module WithSingletonMethod | ||
class ParallelProcess | ||
def split | ||
Digdag.env.store(task_count: 3) | ||
end | ||
|
||
def run(task_count) | ||
task_count.times do |i| | ||
Digdag.env.add_subtask(:subtask, index: i) | ||
end | ||
Digdag.env.subtask_config['_parallel'] = true | ||
end | ||
end | ||
end | ||
|
||
def subtask(index) | ||
puts("Processing" + index.to_s) | ||
end | ||
|
||
# add_subtask(klass, instance_method_name, params={}) | ||
module WithInstanceMethod | ||
class ParallelProcess | ||
def split | ||
Digdag.env.store(task_count: 3) | ||
end | ||
|
||
def run(task_count) | ||
task_count.times do |i| | ||
Digdag.env.add_subtask(ParallelProcess, :subtask, index: i) | ||
end | ||
Digdag.env.subtask_config['_parallel'] = true | ||
end | ||
|
||
def subtask(index) | ||
puts("Processing" + index.to_s) | ||
end | ||
end | ||
end |