From 3b149f0b3c28bb86e0530315fc519713f709ae95 Mon Sep 17 00:00:00 2001 From: KentFujii Date: Sat, 9 Apr 2022 16:47:32 +0900 Subject: [PATCH] add: ruby_examples_for_generating_subtasks --- ...tasks.dig => python_generate_subtasks.dig} | 1 - examples/ruby_generate_subtasks.dig | 23 +++++++ examples/tasks/generate_subtasks.rb | 63 +++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) rename examples/{generate_subtasks.dig => python_generate_subtasks.dig} (99%) create mode 100644 examples/ruby_generate_subtasks.dig create mode 100644 examples/tasks/generate_subtasks.rb diff --git a/examples/generate_subtasks.dig b/examples/python_generate_subtasks.dig similarity index 99% rename from examples/generate_subtasks.dig rename to examples/python_generate_subtasks.dig index 7c2200af58..6be2f6906e 100644 --- a/examples/generate_subtasks.dig +++ b/examples/python_generate_subtasks.dig @@ -5,4 +5,3 @@ timezone: UTC +parallel_process: py>: tasks.generate_subtasks.ParallelProcess.run - diff --git a/examples/ruby_generate_subtasks.dig b/examples/ruby_generate_subtasks.dig new file mode 100644 index 0000000000..c3039674f8 --- /dev/null +++ b/examples/ruby_generate_subtasks.dig @@ -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 diff --git a/examples/tasks/generate_subtasks.rb b/examples/tasks/generate_subtasks.rb new file mode 100644 index 0000000000..7fc964136a --- /dev/null +++ b/examples/tasks/generate_subtasks.rb @@ -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