Last active
November 23, 2016 11:10
-
-
Save jondeandres/93a6500ec34a8c7f93089bb44690baed to your computer and use it in GitHub Desktop.
Fix for DelayedJob + ActiveRecord + Rollbar for max DB text size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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