Skip to content

Commit

Permalink
Merge pull request #1730 from KentFujii/add_ruby_examples_for_generat…
Browse files Browse the repository at this point in the history
…ing_subtasks

add: ruby_examples_for_generating_subtasks
  • Loading branch information
yoyama authored Apr 15, 2022
2 parents 9687645 + 3b149f0 commit 32c7e48
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ timezone: UTC

+parallel_process:
py>: tasks.generate_subtasks.ParallelProcess.run

23 changes: 23 additions & 0 deletions examples/ruby_generate_subtasks.dig
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
63 changes: 63 additions & 0 deletions examples/tasks/generate_subtasks.rb
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

0 comments on commit 32c7e48

Please sign in to comment.