Skip to content

Instantly share code, notes, and snippets.

@jondeandres
Last active November 23, 2016 11:10
Show Gist options
  • Save jondeandres/93a6500ec34a8c7f93089bb44690baed to your computer and use it in GitHub Desktop.
Save jondeandres/93a6500ec34a8c7f93089bb44690baed to your computer and use it in GitHub Desktop.
Fix for DelayedJob + ActiveRecord + Rollbar for max DB text size
require 'rollbar'
require 'rollbar/delay/delayed_job'
require 'delayed/backend/active_record'
module Rollbar
MAX_TEXT_SIZE = 65_535 # Max size for text columns in MySQL
class DelayedHandlerTooLarge < StandardError
end
end
Delayed::Backend::ActiveRecord::Job.class_eval do
before_save do
raise Rollbar::DelayedHandlerTooLarge if handler.size > Rollbar::MAX_TEXT_SIZE
end
end
Rollbar::Delay::DelayedJob.class_eval do
class << self
def call(payload)
new.delay.call(payload)
rescue Rollbar::DelayedHandlerTooLarge
truncate_payload(payload)
retry
end
def truncate_payload(payload)
# Here mutate the payload
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment