Skip to content

Commit

Permalink
support running multiple rake commands via parallel:rake
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed May 18, 2024
1 parent 29c76a2 commit 0028ddf
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions lib/parallel_tests/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,29 @@ def rails_61_or_greater?
ParallelTests::Tasks.run_in_parallel(ParallelTests::Tasks.suppress_schema_load_output(command), args)
end

# define parallel:create and parallel:create:slave etc variants
ParallelTests::Tasks.for_each_database do |name|
task_name = 'create'
task_name += ":#{name}" if name
desc "Create test#{" #{name}" if name} database via db:#{task_name} --> parallel:#{task_name}[num_cpus]"
task task_name.to_sym, :count do |_, args|
task task_name, :count do |_, args|
ParallelTests::Tasks.run_in_parallel(
[$0, "db:#{task_name}", "RAILS_ENV=#{ParallelTests::Tasks.rails_env}"],
[
$0,
"db:#{task_name}",
"RAILS_ENV=#{ParallelTests::Tasks.rails_env}"
],
args
)
end
end

# define parallel:drop and parallel:drop:slave etc variants
ParallelTests::Tasks.for_each_database do |name|
task_name = 'drop'
task_name += ":#{name}" if name
desc "Drop test#{" #{name}" if name} database via db:#{task_name} --> parallel:#{task_name}[num_cpus]"
task task_name.to_sym, :count do |_, args|
task task_name, :count do |_, args|
ParallelTests::Tasks.run_in_parallel(
[
$0,
Expand Down Expand Up @@ -218,12 +224,12 @@ def rails_61_or_greater?
end
end

# when dumping/resetting takes too long
ParallelTests::Tasks.for_each_database do |name|
task_name = 'migrate'
task_name += ":#{name}" if name
# update test database via migrate for when dumping/resetting takes too long
desc "Update test#{" #{name}" if name} database via db:#{task_name} --> parallel:#{task_name}[num_cpus]"
task task_name.to_sym, :count do |_, args|
task task_name, :count do |_, args|
ParallelTests::Tasks.run_in_parallel(
[$0, "db:#{task_name}", "RAILS_ENV=#{ParallelTests::Tasks.rails_env}"],
args
Expand All @@ -241,14 +247,14 @@ def rails_61_or_greater?

# just load the schema (good for integration server <-> no development db)
ParallelTests::Tasks.for_each_database do |name|
rails_task = 'db:schema:load'
rails_task += ":#{name}" if name

task_name = 'load_schema'
task_name += ":#{name}" if name

rails_task = 'db:schema:load'
rails_task += ":#{name}" if name

desc "Load dumped schema for test#{" #{name}" if name} database via #{rails_task} --> parallel:#{task_name}[num_cpus]"
task task_name.to_sym, :count do |_, args|
task task_name, :count do |_, args|
command = [
$0,
ParallelTests::Tasks.purge_before_load,
Expand Down Expand Up @@ -288,10 +294,10 @@ def rails_61_or_greater?
)
end

desc "Launch given rake command in parallel"
desc "Launch given rake commands in parallel"
task :rake, :command, :count do |_, args|
ParallelTests::Tasks.run_in_parallel(
[$0, args.command, "RAILS_ENV=#{ParallelTests::Tasks.rails_env}"],
[$0, *args.command.shellsplit, "RAILS_ENV=#{ParallelTests::Tasks.rails_env}"],
args
)
end
Expand Down

0 comments on commit 0028ddf

Please sign in to comment.