Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: ruby_examples_for_generating_subtasks #1730

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
@@ -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
@@ -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