Skip to content

Instantly share code, notes, and snippets.

@gisikw
Created July 13, 2011 14:19
Show Gist options
  • Save gisikw/1080366 to your computer and use it in GitHub Desktop.
Save gisikw/1080366 to your computer and use it in GitHub Desktop.
Reason for Errors
def enqueue(*args)
object = args.shift
unless object.respond_to?(:perform)
raise ArgumentError, 'Cannot enqueue items which do not respond to perform'
end
priority = args.first || Delayed::Worker.default_priority
run_at = args[1]
self.create(:payload_object => object, :priority => priority.to_i, :run_at => run_at)
end
# Delayed::Job.enqueue takes the first argument as the object, and expects the second object to be a priority int-able, not a hash
define_method "enqueue_job_for_#{name}" do
return unless self.send("#{name}_changed?")
# Paperclip::Attachment#queue_existing_for_delete sets paperclip
# attributes to nil when the record has been marked for deletion
return if self.class::PAPERCLIP_ATTRIBUTES.map { |suff| self.send "#{name}#{suff}" }.compact.empty?
if delayed_job?
Delayed::Job.enqueue(DelayedPaperclipJob.new(self.class.name, read_attribute(:id), name.to_sym), :priority => priority)
elsif resque?
Resque.enqueue(ResquePaperclipJob, self.class.name, read_attribute(:id), name.to_sym)
end
end
# Delayed::Job.enqueue is called with the object passed in as arg[0], and {:priority => 0} as arg[1]
Suggested steps:
- Modify delayed_paperclip/lib/delayed/paperclip.rb:31 to read:
Delayed::Job.enqueue(DelayedPaperclipJob.new(self.class.name, read_attribute(:id), name.to_sym), priority)
(This has been hotfixed in production, and the Study.download_pdf! method passed)
- There is no versioning set up on delayed_paperclip (or indeed on many of these gems). Issue could resurface on subsequent deploys - this should be frozen.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment