ostinelli / apnotic

A Ruby APNs HTTP/2 gem able to provide instant feedback.
MIT License
479 stars 94 forks source link

Usage with Sidekiq / Resque example #125

Closed gnumarcelo closed 1 year ago

gnumarcelo commented 1 year ago

Hi, I just have one doubt about the example provided at the Usage with Sidekiq / Resque: In the example, I can see the error callback being specified: connection.on(:error) { |exception| puts "Exception has been raised: #{exception}" }

But under the Thread-Safety section, it states: "If you're using Apnotic with a job manager you should be fine by not specifying this callback."

My question is, if, using it with Sidekiq and I specify the error callback as in the example, it means that once an error happens it will not trigger Sidekiq retry mechanism, is it correct?

ps.: Thanks for making such a great library!!!

benubois commented 1 year ago

Hi @gnumarcelo,

The error callback is implemented here in net-http2. It looks like exceptions are not re-raised, so I think that exceptions raised in the connection will not trigger an automatic retry:

def callback_or_raise(exception)
  if callback_events.keys.include?(:error)
    emit(:error, exception)
  else
    raise exception
  end
end

You could do something like this to surface the exception for your job, if you also want use an error callback:

APNOTIC_POOL = Apnotic::ConnectionPool.new do |connection|
  connection.on(:error) { |exception| 
    puts "Exception has been raised: #{exception}" 
    raise exception
  }
end

Thanks!