diff --git a/app/models/inbound_webhook.rb b/app/models/inbound_webhook.rb index bc9788c6ebd..8ca86032b92 100644 --- a/app/models/inbound_webhook.rb +++ b/app/models/inbound_webhook.rb @@ -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 @@ -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) diff --git a/app/services/inbound_webhooks/process_service.rb b/app/services/inbound_webhooks/process_service.rb index 2ac844b7ba8..9990396ecec 100644 --- a/app/services/inbound_webhooks/process_service.rb +++ b/app/services/inbound_webhooks/process_service.rb @@ -2,8 +2,6 @@ module InboundWebhooks class ProcessService < BaseService - WEBHOOK_PROCESSING_WINDOW = 2.hours - WEBHOOK_HANDLER_SERVICES = { stripe: PaymentProviders::Stripe::HandleIncomingWebhookService } @@ -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