thoughtbot / parity

Shell commands for development, staging, and production parity for Heroku apps
https://thoughtbot.com
MIT License
895 stars 57 forks source link

Allow pre-2.2 Rubies to execute `development restore` #144

Closed geoffharcourt closed 6 years ago

geoffharcourt commented 6 years ago

In #143, we got a report that because Etc.nprocessors was not implemented until Ruby 2.2 that Ruby 2.1 users were unable to execute development restore, which leverages that method to determine how many parallel processes to use when restoring the backup from the downloaded dump.

This change implements a check to see if Etc.nprocessors is available. In the event that it's not, we'll default to two parallel processes. We will plan to sunset this change in July 2018, giving users on Ruby 2.1, which has been EOLed, six months to move on.

Close #143.

mike-burns commented 6 years ago
  1. LGTM.
  2. That said, since we plan to remove this code, is there a way that makes this more obvious? Maybe something like:
def restore_from_local_temp_backup
  Kernel.system(
    "pg_restore tmp/latest.backup --verbose --clean --no-acl --no-owner "\
    "--dbname #{development_db} --jobs #{processor_cores} "\
    "#{additional_args}",
  )
end

def processor_cores
  if ruby_version_over_2_2
    Etc.nprocessors
  else
    2
  end
end

def ruby_version_over_2_2
  Etc.respond_to?(:nprocessors)
end