Skip to content

Instantly share code, notes, and snippets.

@iloveitaly
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iloveitaly/9252194 to your computer and use it in GitHub Desktop.
Save iloveitaly/9252194 to your computer and use it in GitHub Desktop.
# app/middleware/disable_assets_logger.rb
# https://github.com/rails/rails/issues/2639#issuecomment-6591735
# http://stackoverflow.com/questions/6312448/how-to-disable-logging-of-asset-pipeline-sprockets-messages-in-rails-3-1
class DisableAssetsLogger
def initialize(app)
@app = app
Rails.application.assets.logger = Logger.new('/dev/null')
end
def call(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
@app.call(env)
ensure
Rails.logger.level = previous_level
end
end
# /etc/log_files.yml
files:
- /data/spree/shared/log/production.log
- /data/spree/shared/log/unicorn.stderr.log
- /data/spree/shared/log/sunspot-solr-production.log
- /data/spree/shared/log/ups.log
- /data/spree/shared/log/usps.log
- /data/spree/shared/log/delayed_job.log
- /data/spree/shared/log/netsuite.log
- /var/log/cron.log
destination:
host: logs.papertrailapp.com
port: 44690
file { "/etc/logrotate.d/yourdomain_com":
ensure => file,
owner => root,
group => root,
content => "
/data/spree/current/log/production.log
/data/spree/current/log/unicorn.stderr.log
/data/spree/current/log/ups.log
/data/spree/current/log/usps.log
/data/spree/current/log/backup.log
{
size=10M
missingok
dateext
copytruncate
compress
delaycompress
notifempty
rotate 365
}
"
}
# backup/models/mysql_backup.rb
Backup::Model.new(:mysql_backup, 'MySQL + Files') do
database MySQL do |db|
# To dump all databases, set `db.name = :all` (or leave blank)
db.name = "spree"
db.username = "spree"
db.password = "spree"
db.socket = "/var/run/mysqld/mysqld.sock"
end
# mysql backup
store_with S3 do |s3|
s3.access_key_id = 'yourid'
s3.secret_access_key = 'yourkey'
s3.region = 'us-east-1'
s3.bucket = 'your-bucket/spree/database'
s3.keep = 365
end
# uploaded files backup
sync_with Cloud::S3 do |s3|
s3.access_key_id = "yourid"
s3.secret_access_key = "yourkey"
s3.bucket = "your-backup"
s3.path = "/spree/uploads"
s3.mirror = true
s3.directories do |directory|
directory.add "/data/spree/shared/uploaded-files"
directory.add "/data/spree/shared/system"
end
end
compress_with Gzip
# https://github.com/meskyanichi/backup/wiki/Notifiers
notify_by Mail do |mail|
mail.on_success = true
mail.on_warning = true
mail.on_failure = true
mail.from = "from@domain.com"
mail.to = "to@domain.com"
mail.address = "smtp.sendgrid.net"
mail.port = 587
# mail.domain = "smtp.sendgrid.net"
mail.user_name = "sendgridusername"
mail.password = "sendgridpassword"
mail.authentication = "plain"
mail.encryption = :starttls
end
end
Spree::Payment.class_eval do
def gateway_error(error)
if error.is_a? ActiveMerchant::Billing::Response
text = error.params['message'] || error.params['response_reason_text'] || error.message
elsif error.is_a? ActiveMerchant::ConnectionError
text = I18n.t(:unable_to_connect_to_gateway)
else
text = error.to_s
end
logger.error(I18n.t(:gateway_error))
logger.error(" #{error.to_yaml}")
exc = Spree::Core::GatewayError.new(text)
Airbrake.notify exc, :parameters => (error.is_a? ActiveMerchant::Billing::Response)? error.params : {}
raise exc
end
end
YourApplication::Application.configure do
config.lograge.enabled = true
config.lograge.custom_options = lambda do |event|
params = event.payload[:params].reject do |k|
['controller', 'action'].include? k
end
{ "params" => params }
end
config.middleware.swap(
Rails::Rack::Logger, Ciunas::Logger,
:silenced => [
# "/noisy/action.json",
/d24fvsfc6m7i1u\.cloudfront\.net.*/,
/shop\/ProdImages\/.*/,
/shop\/images\/.*/
]
)
end
env :PATH, ENV['PATH']
set :output, "/var/log/cron.log"
set :path, '/data/spree/current'
every 1.day, :at => '5:20 am' do
# TODO this path should be able to be dynamic
command "cd /data/spree/current && backup perform -t mysql_backup -c /data/spree/current/backup/config.rb"
end
# per amy USPS media mail should not be available if item total above
# $100 orders via media mail cannot be insured
Spree::Calculator::Usps::MediaMail.class_eval do
old_available = instance_method(:available?)
define_method :available? do |order|
return false if order.item_total > 100.0
old_available.bind(self).(order)
end
end
# when we are testing, we want to see the errors...
if Rails.env.test? or Rails.env.development?
Spree::OrdersController.class_eval do
private
def handle_shipping_error(e)
raise e
end
end
Spree::CheckoutController.class_eval do
private
def handle_shipping_error(e)
raise e
end
end
else
# in production, push all errors to airbrake
Spree::OrdersController.class_eval do
private
def handle_shipping_error(e)
Airbrake.notify e
flash[:error] = e.message
redirect_to checkout_state_path(:address)
end
end
Spree::CheckoutController.class_eval do
private
def handle_shipping_error(e)
Airbrake.notify e
flash[:error] = e.message
redirect_to checkout_state_path(:address)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment