Module: Que::Utils::ErrorNotification
- Included in:
- Que
- Defined in:
- lib/que/utils/error_notification.rb
Constant Summary collapse
- ASYNC_QUEUE =
Queue.new
- MAX_QUEUE_SIZE =
5
Instance Attribute Summary collapse
-
#error_notifier ⇒ Object
Returns the value of attribute error_notifier.
Instance Method Summary collapse
- #async_error_thread ⇒ Object
- #notify_error(*args) ⇒ Object
-
#notify_error_async(*args) ⇒ Object
Helper method to notify errors asynchronously.
Instance Attribute Details
#error_notifier ⇒ Object
Returns the value of attribute error_notifier.
6 7 8 |
# File 'lib/que/utils/error_notification.rb', line 6 def error_notifier @error_notifier end |
Instance Method Details
#async_error_thread ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/que/utils/error_notification.rb', line 57 def async_error_thread CONFIG_MUTEX.synchronize do @async_error_thread ||= Thread.new do Thread.current.abort_on_exception = true loop { Que.notify_error(*ASYNC_QUEUE.pop) } end end end |
#notify_error(*args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/que/utils/error_notification.rb', line 8 def notify_error(*args) Que.internal_log(:error_notification_attempted) do {args: args.inspect} end if notifier = error_notifier arity = notifier.arity args = args.first(arity) if arity >= 0 notifier.call(*args) end rescue => error Que.log( event: :error_notifier_failed, level: :error, message: "error_notifier callable raised an error", error_class: error.class.name, error_message: error., error_backtrace: error.backtrace, ) nil end |
#notify_error_async(*args) ⇒ Object
Helper method to notify errors asynchronously. For use in high-priority code, where we don’t want to be held up by whatever I/O the error notification proc contains.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/que/utils/error_notification.rb', line 38 def notify_error_async(*args) # We don't synchronize around the size check and the push, so there's a # race condition where the queue could grow to more than the maximum # number of errors, but no big deal if it does. The size check is mainly # here to ensure that the error queue doesn't grow unboundedly large in # pathological cases. if ASYNC_QUEUE.size < MAX_QUEUE_SIZE ASYNC_QUEUE.push(args) # Puma raises some ugly warnings if you start up a new thread in the # background during initialization, so start the async error-reporting # thread lazily. async_error_thread true else false end end |