Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorcruz committed Dec 19, 2024
1 parent f7e5254 commit eb955bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 4 additions & 2 deletions app/models/inbound_webhook.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class InboundWebhook < ApplicationRecord
WEBHOOK_PROCESSING_WINDOW = 2.hours

belongs_to :organization

validates :event_type, :payload, :source, :status, presence: true
Expand All @@ -15,8 +17,8 @@ class InboundWebhook < ApplicationRecord
enum :status, STATUSES

scope :retriable, -> { reprocessable.or(old_pending) }
scope :reprocessable, -> { processing.where("processing_at <= ?", 2.hours.ago) }
scope :old_pending, -> { pending.where("created_at <= ?", 2.hours.ago) }
scope :reprocessable, -> { processing.where("processing_at <= ?", WEBHOOK_PROCESSING_WINDOW.ago) }
scope :old_pending, -> { pending.where("created_at <= ?", WEBHOOK_PROCESSING_WINDOW.ago) }

def processing!
update!(status: :processing, processing_at: Time.zone.now)
Expand Down
4 changes: 1 addition & 3 deletions app/services/inbound_webhooks/process_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

module InboundWebhooks
class ProcessService < BaseService
WEBHOOK_PROCESSING_WINDOW = 2.hours

WEBHOOK_HANDLER_SERVICES = {
stripe: PaymentProviders::Stripe::HandleIncomingWebhookService
}
Expand Down Expand Up @@ -52,7 +50,7 @@ def webhook_source
end

def within_processing_window?
inbound_webhook.processing? && inbound_webhook.processing_at > WEBHOOK_PROCESSING_WINDOW.ago
inbound_webhook.processing? && inbound_webhook.processing_at > InboundWebhook::WEBHOOK_PROCESSING_WINDOW.ago
end
end
end

0 comments on commit eb955bc

Please sign in to comment.