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

cleanup task logic more #737

Merged
merged 1 commit into from
Dec 10, 2019
Merged

cleanup task logic more #737

merged 1 commit into from
Dec 10, 2019

Conversation

grosser
Copy link
Owner

@grosser grosser commented Dec 9, 2019

@ndbroadbent looks good ?

Copy link
Contributor

@ndbroadbent ndbroadbent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grosser That looks good! I think there's a bug with the task_name variable, but I think it is better to be more explicit. Maybe something like this?

  desc "Update test databases by dumping and loading --> parallel:prepare[num_cpus]"
  task(:prepare, [:count]) do |_,args|
    ParallelTests::Tasks.check_for_pending_migrations
    if defined?(ActiveRecord::Base) && [:ruby, :sql].include?(ActiveRecord::Base.schema_format)
      # fast: dump once, load in parallel
      case ActiveRecord::Base.schema_format
      when :ruby
        Rake::Task["db:schema:dump"].invoke
        ActiveRecord::Base.remove_connection if ActiveRecord::Base.configurations.any?
        Rake::Task["parallel:load_schema"].invoke(args[:count])
      when :sql
        Rake::Task["db:structure:dump"].invoke
        ActiveRecord::Base.remove_connection if ActiveRecord::Base.configurations.any?
        Rake::Task["parallel:load_structure"].invoke(args[:count])
      end
    else
      # slow: dump and load in in serial
      args = args.to_hash.merge(:non_parallel => true) # normal merge returns nil
      task_name = Rake::Task.task_defined?('db:test:prepare') ? 'db:test:prepare' : 'app:db:test:prepare'
      ParallelTests::Tasks.run_in_parallel("#{ParallelTests::Tasks.rake_bin} #{task_name}", args)
    end
  end

if defined?(ActiveRecord::Base) && [:ruby, :sql].include?(ActiveRecord::Base.schema_format)
# fast: dump once, load in parallel
task_name = (ActiveRecord::Base.schema_format == :ruby ? "parallel:load_schema" : "parallel:load_structure")
Rake::Task["db:#{task_name}:dump"].invoke
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

task_name is used here, so this will become: Rake::Task["db:parallel:load_schema:dump"].invoke

@grosser grosser merged commit f366a1b into master Dec 10, 2019
@grosser grosser deleted the grosser/clean branch December 10, 2019 05:45
@grosser
Copy link
Owner Author

grosser commented Dec 10, 2019

2.30.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants