arthurnn / apn_sender

Background worker to send Apple Push Notifications over a persistent TCP socket.
MIT License
377 stars 146 forks source link

Resque workers fail to run #48

Open abscondment opened 11 years ago

abscondment commented 11 years ago

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...

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.

arthurnn commented 10 years ago

Can you try latest master to see if solves the issue?

thanks