Sha256: 2126bdbdc5cc6288b26bfe6d138743ee6570bc1a474045b7099946e06290b9bd

Contents?: true

Size: 1.58 KB

Versions: 36

Compression:

Stored size: 1.58 KB

Contents

module Rpush
  module Daemon
    class Delivery
      include Reflectable
      include Loggable

      def mark_retryable(notification, deliver_after, error = nil)
        if notification.fail_after && notification.fail_after < Time.now
          @batch.mark_failed(notification, nil, "Notification failed to be delivered before #{notification.fail_after.strftime('%Y-%m-%d %H:%M:%S')}.")
        else
          if error
            log_warn("Will retry notification #{notification.id} after #{deliver_after.strftime('%Y-%m-%d %H:%M:%S')} due to error (#{error.class.name}, #{error.message})")
          end
          @batch.mark_retryable(notification, deliver_after)
        end
      end

      def mark_retryable_exponential(notification)
        mark_retryable(notification, Time.now + 2**(notification.retries + 1))
      end

      def mark_batch_retryable(deliver_after, error)
        log_warn("Will retry #{@batch.notifications.size} notifications after #{deliver_after.strftime('%Y-%m-%d %H:%M:%S')} due to error (#{error.class.name}, #{error.message})")
        @batch.mark_all_retryable(deliver_after)
      end

      def mark_delivered
        @batch.mark_delivered(@notification)
      end

      def mark_batch_delivered
        @batch.mark_all_delivered
      end

      def mark_failed(error)
        code = error.respond_to?(:code) ? error.code : nil
        @batch.mark_failed(@notification, code, error.to_s)
      end

      def mark_batch_failed(error)
        code = error.respond_to?(:code) ? error.code : nil
        @batch.mark_all_failed(code, error.to_s)
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
rpush-5.1.0 lib/rpush/daemon/delivery.rb
rpush-5.0.0 lib/rpush/daemon/delivery.rb
rpush-4.2.0 lib/rpush/daemon/delivery.rb
rpush-4.1.1 lib/rpush/daemon/delivery.rb
rpush-4.1.0 lib/rpush/daemon/delivery.rb
rpush-4.0.1 lib/rpush/daemon/delivery.rb
rpush-4.0.0 lib/rpush/daemon/delivery.rb
rpush-3.3.1 lib/rpush/daemon/delivery.rb
rpush-3.3.0 lib/rpush/daemon/delivery.rb
rpush_extended-3.2.6 lib/rpush/daemon/delivery.rb
rpush_extended-3.2.5 lib/rpush/daemon/delivery.rb
rpush-3.2.4 lib/rpush/daemon/delivery.rb
rpush-3.2.3 lib/rpush/daemon/delivery.rb
rpush-3.2.2 lib/rpush/daemon/delivery.rb
rpush-3.2.1 lib/rpush/daemon/delivery.rb
rpush-3.2.0 lib/rpush/daemon/delivery.rb
rpush-3.1.1 lib/rpush/daemon/delivery.rb
rpush-3.1.0 lib/rpush/daemon/delivery.rb
rpush-3.0.2 lib/rpush/daemon/delivery.rb
rpush-3.0.1 lib/rpush/daemon/delivery.rb