Class: PactBroker::Webhooks::Service
Constant Summary
collapse
- RESOURCE_CREATION =
PactBroker::Webhooks::TriggeredWebhook::TRIGGER_TYPE_RESOURCE_CREATION
- USER =
PactBroker::Webhooks::TriggeredWebhook::TRIGGER_TYPE_USER
Class Method Summary
collapse
-
.create(uuid, webhook, consumer, provider) ⇒ Object
-
.delete_all_webhhook_related_objects_by_pacticipant(pacticipant) ⇒ Object
-
.delete_all_webhook_related_objects_by_pact_publication_ids(pact_publication_ids) ⇒ Object
-
.delete_by_uuid(uuid) ⇒ Object
-
.errors(webhook) ⇒ Object
-
.execute_triggered_webhook_now(triggered_webhook, options) ⇒ Object
-
.execute_webhook_now(webhook, pact, verification = nil) ⇒ Object
-
.fail_retrying_triggered_webhooks ⇒ Object
-
.find_all ⇒ Object
-
.find_by_consumer_and_or_provider(consumer, provider) ⇒ Object
-
.find_by_consumer_and_provider(consumer, provider) ⇒ Object
-
.find_by_uuid(uuid) ⇒ Object
-
.find_for_pact(pact) ⇒ Object
-
.find_latest_triggered_webhooks(consumer, provider) ⇒ Object
-
.find_latest_triggered_webhooks_for_pact(pact) ⇒ Object
-
.find_triggered_webhooks_for_pact(pact) ⇒ Object
-
.find_triggered_webhooks_for_verification(verification) ⇒ Object
-
.job_database_connector ⇒ Object
-
.next_uuid ⇒ Object
-
.run_later(webhooks, pact, verification, event_name) ⇒ Object
-
.test_execution(webhook) ⇒ Object
-
.trigger_webhooks(pact, verification, event_name) ⇒ Object
-
.update_by_uuid(uuid, webhook) ⇒ Object
-
.update_triggered_webhook_status(triggered_webhook, status) ⇒ Object
label_repository, matrix_repository, pact_repository, pacticipant_repository, tag_repository, verification_repository, version_repository, webhook_repository
Methods included from Services
badge_service, certificate_service, group_service, index_service, label_service, matrix_service, pact_service, pacticipant_service, tag_service, verification_service, version_service, webhook_service
Methods included from Logging
included, #log_error
Class Method Details
.create(uuid, webhook, consumer, provider) ⇒ Object
35
36
37
|
# File 'lib/pact_broker/webhooks/service.rb', line 35
def self.create uuid, webhook, consumer, provider
webhook_repository.create uuid, webhook, consumer, provider
end
|
52
53
54
55
56
|
# File 'lib/pact_broker/webhooks/service.rb', line 52
def self.delete_all_webhhook_related_objects_by_pacticipant pacticipant
webhook_repository.delete_executions_by_pacticipant pacticipant
webhook_repository.delete_triggered_webhooks_by_pacticipant pacticipant
webhook_repository.delete_by_pacticipant pacticipant
end
|
58
59
60
|
# File 'lib/pact_broker/webhooks/service.rb', line 58
def self.delete_all_webhook_related_objects_by_pact_publication_ids pact_publication_ids
webhook_repository.delete_triggered_webhooks_by_pact_publication_ids pact_publication_ids
end
|
.delete_by_uuid(uuid) ⇒ Object
47
48
49
50
|
# File 'lib/pact_broker/webhooks/service.rb', line 47
def self.delete_by_uuid uuid
webhook_repository.delete_triggered_webhooks_by_webhook_uuid uuid
webhook_repository.delete_by_uuid uuid
end
|
.errors(webhook) ⇒ Object
29
30
31
32
33
|
# File 'lib/pact_broker/webhooks/service.rb', line 29
def self.errors webhook
contract = PactBroker::Api::Contracts::WebhookContract.new(webhook)
contract.validate(webhook.attributes)
contract.errors
end
|
.execute_triggered_webhook_now(triggered_webhook, options) ⇒ Object
89
90
91
92
93
|
# File 'lib/pact_broker/webhooks/service.rb', line 89
def self.execute_triggered_webhook_now triggered_webhook, options
webhook_execution_result = triggered_webhook.execute options.merge(show_response: PactBroker.configuration.show_webhook_response?)
webhook_repository.create_execution triggered_webhook, webhook_execution_result
webhook_execution_result
end
|
.execute_webhook_now(webhook, pact, verification = nil) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/pact_broker/webhooks/service.rb', line 77
def self.execute_webhook_now webhook, pact, verification = nil
triggered_webhook = webhook_repository.create_triggered_webhook(next_uuid, webhook, pact, verification, USER)
options = { failure_log_message: "Webhook execution failed"}
webhook_execution_result = execute_triggered_webhook_now triggered_webhook, options
if webhook_execution_result.success?
webhook_repository.update_triggered_webhook_status triggered_webhook, TriggeredWebhook::STATUS_SUCCESS
else
webhook_repository.update_triggered_webhook_status triggered_webhook, TriggeredWebhook::STATUS_FAILURE
end
webhook_execution_result
end
|
.fail_retrying_triggered_webhooks ⇒ Object
151
152
153
|
# File 'lib/pact_broker/webhooks/service.rb', line 151
def self.fail_retrying_triggered_webhooks
webhook_repository.fail_retrying_triggered_webhooks
end
|
.find_all ⇒ Object
62
63
64
|
# File 'lib/pact_broker/webhooks/service.rb', line 62
def self.find_all
webhook_repository.find_all
end
|
.find_by_consumer_and_or_provider(consumer, provider) ⇒ Object
103
104
105
|
# File 'lib/pact_broker/webhooks/service.rb', line 103
def self.find_by_consumer_and_or_provider consumer, provider
webhook_repository.find_by_consumer_and_or_provider(consumer, provider)
end
|
.find_by_consumer_and_provider(consumer, provider) ⇒ Object
107
108
109
|
# File 'lib/pact_broker/webhooks/service.rb', line 107
def self.find_by_consumer_and_provider consumer, provider
webhook_repository.find_by_consumer_and_provider consumer, provider
end
|
.find_by_uuid(uuid) ⇒ Object
39
40
41
|
# File 'lib/pact_broker/webhooks/service.rb', line 39
def self.find_by_uuid uuid
webhook_repository.find_by_uuid uuid
end
|
.find_for_pact(pact) ⇒ Object
99
100
101
|
# File 'lib/pact_broker/webhooks/service.rb', line 99
def self.find_for_pact pact
webhook_repository.find_for_pact(pact)
end
|
.find_latest_triggered_webhooks(consumer, provider) ⇒ Object
147
148
149
|
# File 'lib/pact_broker/webhooks/service.rb', line 147
def self.find_latest_triggered_webhooks consumer, provider
webhook_repository.find_latest_triggered_webhooks consumer, provider
end
|
.find_latest_triggered_webhooks_for_pact(pact) ⇒ Object
143
144
145
|
# File 'lib/pact_broker/webhooks/service.rb', line 143
def self.find_latest_triggered_webhooks_for_pact pact
webhook_repository.find_latest_triggered_webhooks_for_pact pact
end
|
.find_triggered_webhooks_for_pact(pact) ⇒ Object
155
156
157
|
# File 'lib/pact_broker/webhooks/service.rb', line 155
def self.find_triggered_webhooks_for_pact pact
webhook_repository.find_triggered_webhooks_for_pact(pact)
end
|
.find_triggered_webhooks_for_verification(verification) ⇒ Object
159
160
161
|
# File 'lib/pact_broker/webhooks/service.rb', line 159
def self.find_triggered_webhooks_for_verification verification
webhook_repository.find_triggered_webhooks_for_verification(verification)
end
|
.job_database_connector ⇒ Object
139
140
141
|
# File 'lib/pact_broker/webhooks/service.rb', line 139
def self.job_database_connector
Thread.current[:pact_broker_thread_data].database_connector
end
|
.next_uuid ⇒ Object
25
26
27
|
# File 'lib/pact_broker/webhooks/service.rb', line 25
def self.next_uuid
SecureRandom.urlsafe_base64
end
|
.run_later(webhooks, pact, verification, event_name) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/pact_broker/webhooks/service.rb', line 121
def self.run_later webhooks, pact, verification, event_name
trigger_uuid = next_uuid
webhooks.each do | webhook |
begin
triggered_webhook = webhook_repository.create_triggered_webhook(trigger_uuid, webhook, pact, verification, RESOURCE_CREATION)
logger.info "Scheduling job for #{webhook.description} with uuid #{webhook.uuid}"
job_data = {
triggered_webhook: triggered_webhook,
database_connector: job_database_connector
}
Job.perform_in(5, job_data)
rescue StandardError => e
log_error e
end
end
end
|
.test_execution(webhook) ⇒ Object
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/pact_broker/webhooks/service.rb', line 66
def self.test_execution webhook
options = { failure_log_message: "Webhook execution failed", show_response: PactBroker.configuration.show_webhook_response?}
verification = nil
if webhook.trigger_on_provider_verification_published?
verification = verification_service.search_for_latest(webhook.consumer_name, webhook.provider_name) || PactBroker::Verifications::PlaceholderVerification.new
end
pact = pact_service.search_for_latest_pact(consumer_name: webhook.consumer_name, provider_name: webhook.provider_name) || PactBroker::Pacts::PlaceholderPact.new
webhook.execute(pact, verification, options)
end
|
.trigger_webhooks(pact, verification, event_name) ⇒ Object
111
112
113
114
115
116
117
118
119
|
# File 'lib/pact_broker/webhooks/service.rb', line 111
def self.trigger_webhooks pact, verification, event_name
webhooks = webhook_repository.find_by_consumer_and_or_provider_and_event_name pact.consumer, pact.provider, event_name
if webhooks.any?
run_later(webhooks, pact, verification, event_name)
else
logger.debug "No webhook found for consumer \"#{pact.consumer.name}\" and provider \"#{pact.provider.name}\""
end
end
|
.update_by_uuid(uuid, webhook) ⇒ Object
43
44
45
|
# File 'lib/pact_broker/webhooks/service.rb', line 43
def self.update_by_uuid uuid, webhook
webhook_repository.update_by_uuid uuid, webhook
end
|
.update_triggered_webhook_status(triggered_webhook, status) ⇒ Object
95
96
97
|
# File 'lib/pact_broker/webhooks/service.rb', line 95
def self.update_triggered_webhook_status triggered_webhook, status
webhook_repository.update_triggered_webhook_status triggered_webhook, status
end
|