Skip to content

Instantly share code, notes, and snippets.

@chrismcg
Created October 15, 2012 14:18
Show Gist options
  • Save chrismcg/3892678 to your computer and use it in GitHub Desktop.
Save chrismcg/3892678 to your computer and use it in GitHub Desktop.
Config for running Localeapp in staging/production on Heroku
- poll every 5 minutes on :staging env
- poll on deployment only on :production env (not only dyno restart)
This assumes you've setup separate production/staging environments as described in:
https://devcenter.heroku.com/articles/multiple-environments
Especially the part about setting the RAILS_ENV/RACK_ENV on the staging environment.
The "polling" on deployment takes advantage of the fact that heroku runs the
asset:precompile task as part of building a slug. We hook into that to run the
fetch from locale app. You could avoid this by always pulling and committing
locally before pushing to heroku.
We also take advantage of any code in initializers being run at rails boot up
to pull the translations in staging every time the dyno restarts.
# lib/tasks/localeapp.rake
namespace :localeapp do
desc "Fetch the latest translations from localeapp.com"
task :fetch_latest_translations => [:environment] do
if Rails.env.production? || Rails.env.staging?
Localeapp::CLI::Pull.new.execute
end
end
end
Rake::Task['assets:precompile'].enhance ['localeapp:fetch_latest_translations']
# config/initializers/localeapp.rb
require 'localeapp/rails'
Localeapp.configure do |config|
config.api_key = '<API KEY>'
config.poll_interval = 300 if Rails.env.staging?
config.polling_environments = [:development, :staging]
config.reloading_environments = [:development, :staging]
config.sending_environments = [:development, :staging]
end
# Pull latest when dyno restarts on staging
if Rails.env.staging?
Localeapp::CLI::Pull.new.execute
end
@jerome
Copy link

jerome commented Oct 15, 2012

(not only dyno restart)

Does it mean it also fetches on dyno restart ?

@chrismcg
Copy link
Author

Sorry @jerome, only saw your comment now. In the configuration above it will fetch on dyno restart in the staging environment only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment