Skip to content

Commit

Permalink
refactor: move main method to top of file
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 26, 2023
1 parent 50fde25 commit 74f049b
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/pact_broker/webhooks/trigger_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ module TriggerService
include PactBroker::Logging
using PactBroker::HashRefinements

# the main entry point
def create_triggered_webhooks_for_event pact, verification, event_name, event_context
webhooks = webhook_repository.find_webhooks_to_trigger(consumer: pact.consumer, provider: pact.provider, event_name: event_name)

if webhooks.any?
create_triggered_webhooks_for_webhooks(webhooks, pact, verification, event_name, event_context.merge(event_name: event_name))
else
[]
end
end

def next_uuid
SecureRandom.uuid
end

# TODO support currently deployed
def test_execution webhook, event_context, execution_configuration
merged_options = execution_configuration.with_failure_log_message("Webhook execution failed").to_hash

Expand All @@ -36,17 +46,6 @@ def execute_triggered_webhook_now triggered_webhook, webhook_execution_configura
webhook_execution_result
end

# the main entry point
def create_triggered_webhooks_for_event pact, verification, event_name, event_context
webhooks = webhook_repository.find_webhooks_to_trigger(consumer: pact.consumer, provider: pact.provider, event_name: event_name)

if webhooks.any?
create_triggered_webhooks_for_webhooks(webhooks, pact, verification, event_name, event_context.merge(event_name: event_name))
else
[]
end
end

def schedule_webhooks(triggered_webhooks, options)
triggered_webhooks.each_with_index do | triggered_webhook, i |
logger.info "Scheduling job for webhook with uuid #{triggered_webhook.webhook.uuid}, context: #{triggered_webhook.event_context}"
Expand Down

0 comments on commit 74f049b

Please sign in to comment.