Skip to content

Commit

Permalink
configure s3_bucket name in one place, rescue exceptions in qr_code task
Browse files Browse the repository at this point in the history
  • Loading branch information
msimonborg committed Aug 23, 2017
1 parent c7cb425 commit c0bbf59
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/office_location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class OfficeLocation < ApplicationRecord

# Set a "PYR_S3_BUCKET" environment variable to your own S3 Bucket
# if you want to use your own generated QR Codes.
S3_BUCKET = ENV.fetch('PYR_S3_BUCKET') { 'phone-your-rep-images' }.freeze
S3_BUCKET = Rails.configuration.s3_bucket

belongs_to :rep, foreign_key: :official_id, primary_key: :official_id
has_many :issues
Expand Down
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ class Application < Rails::Application

# Use Rack::Attack to deter malicious attacks by throttling requests by IP.
config.middleware.use Rack::Attack

# Set the S3 Bucket name for QR codes
config.s3_bucket = ENV.fetch('PYR_S3_BUCKET') { 'phone-your-rep-images' }
end
end
12 changes: 8 additions & 4 deletions lib/tasks/qr_codes.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace :pyr do
# Set the "PYR_S3_BUCKET" environment variable on your machine or
# at the command line (e.g. `rake some_task PYR_S3_BUCKET=your-own-bucket`)
# if you wish to generate and upload your own images.
S3_BUCKET = ENV['PYR_S3_BUCKET']
S3_BUCKET = Rails.configuration.s3_bucket

desc 'Generate QR code images for all office locations'
task :generate, [:rep_set] do |_t, args|
Expand Down Expand Up @@ -81,9 +81,13 @@ namespace :pyr do
FileUtils.mv(filename, "../../../../../../../../qr_codes/#{args[:rep_set]}/#{filename}")
end
end
Dir.chdir('../qr_codes') do
sh "git add #{args[:rep_set]}/*.png && git commit -m "\
"'update QR codes #{Time.now}' && git push"
begin
Dir.chdir('../qr_codes') do
sh "git add #{args[:rep_set]}/*.png && git commit -m "\
"'update QR codes #{Time.now}' && git push"
end
rescue RuntimeError => e
Rails.logger.error e
end
end

Expand Down

0 comments on commit c0bbf59

Please sign in to comment.