Let's look at the example from apn/tasks:
APN.password = ENV['CERT_PASS']
APN.full_certificate_path = ENV['FULL_CERT_PATH']
APN.logger = Rails.logger
worker = ::Resque::Worker.new(APN::Jobs::QUEUE_NAME)
puts "*** Starting worker to send apple notifications in the background from #{worker}"
worker.work(ENV['INTERVAL'] || 5) # interval, will block
This starts just fine. However...
require 'apn/jobs/resque_notification_job' is now run inside the backend method.
- The queue uses the job class
APN::Jobs::ResqueNotificationJob.
So, since we've never called APN.backend in this worker (and we shouldn't have to do that!), the first queue item will crash when attempting to reference the un-loaded ResqueNotificationJob class.
I think the solution should load the job classes up front, rather than requiring a backend (which the workers won't even use) to be created.
How do you feel about trying to require both sidekiq and resque, like below?
begin
require 'sidekiq'
require 'apn/jobs/sidekiq_notification_job'
rescue LoadError
end
begin
require 'resque'
require 'apn/jobs/resque_notification_job'
rescue LoadError
end
This solves my problems, although it feels a little less than clean. If it's fine with you, I'll send a pull request.
Let's look at the example from
apn/tasks:This starts just fine. However...
require 'apn/jobs/resque_notification_job'is now run inside thebackendmethod.APN::Jobs::ResqueNotificationJob.So, since we've never called
APN.backendin this worker (and we shouldn't have to do that!), the first queue item will crash when attempting to reference the un-loaded ResqueNotificationJob class.I think the solution should load the job classes up front, rather than requiring a backend (which the workers won't even use) to be created.
How do you feel about trying to require both sidekiq and resque, like below?
This solves my problems, although it feels a little less than clean. If it's fine with you, I'll send a pull request.