Class: PactBroker::Webhooks::Service
- Inherits:
-
Object
- Object
- PactBroker::Webhooks::Service
show all
- Extended by:
- Repositories
- Includes:
- Logging
- Defined in:
- lib/pact_broker/webhooks/service.rb
Constant Summary
Constants included
from Logging
Logging::LOG_DIR, Logging::LOG_FILE_NAME
Class Method Summary
collapse
pact_repository, pacticipant_repository, tag_repository, verification_repository, version_repository, webhook_repository
Methods included from Logging
included, #log_error, #logger, #logger=
Class Method Details
.create(uuid, webhook, consumer, provider) ⇒ Object
25
26
27
|
# File 'lib/pact_broker/webhooks/service.rb', line 25
def self.create uuid, webhook, consumer, provider
webhook_repository.create uuid, webhook, consumer, provider
end
|
.delete_by_pacticipant(pacticipant) ⇒ Object
38
39
40
|
# File 'lib/pact_broker/webhooks/service.rb', line 38
def self.delete_by_pacticipant pacticipant
webhook_repository.delete_by_pacticipant pacticipant
end
|
.delete_by_uuid(uuid) ⇒ Object
33
34
35
36
|
# File 'lib/pact_broker/webhooks/service.rb', line 33
def self.delete_by_uuid uuid
webhook_repository.unlink_executions_by_webhook_uuid uuid
webhook_repository.delete_by_uuid uuid
end
|
.errors(webhook) ⇒ Object
19
20
21
22
23
|
# File 'lib/pact_broker/webhooks/service.rb', line 19
def self.errors webhook
contract = PactBroker::Api::Contracts::WebhookContract.new(webhook)
contract.validate(webhook.attributes)
contract.errors
end
|
.execute_webhook_now(webhook) ⇒ Object
46
47
48
49
50
|
# File 'lib/pact_broker/webhooks/service.rb', line 46
def self.execute_webhook_now webhook
webhook_execution_result = webhook.execute
webhook_repository.create_execution webhook, webhook_execution_result
webhook_execution_result
end
|
.execute_webhooks(pact) ⇒ Object
56
57
58
59
60
61
62
63
64
|
# File 'lib/pact_broker/webhooks/service.rb', line 56
def self.execute_webhooks pact
webhooks = webhook_repository.find_by_consumer_and_provider pact.consumer, pact.provider
if webhooks.any?
run_later(webhooks)
else
logger.debug "No webhook found for consumer \"#{pact.consumer.name}\" and provider \"#{pact.provider.name}\""
end
end
|
.find_all ⇒ Object
42
43
44
|
# File 'lib/pact_broker/webhooks/service.rb', line 42
def self.find_all
webhook_repository.find_all
end
|
.find_by_consumer_and_provider(consumer, provider) ⇒ Object
52
53
54
|
# File 'lib/pact_broker/webhooks/service.rb', line 52
def self.find_by_consumer_and_provider consumer, provider
webhook_repository.find_by_consumer_and_provider consumer, provider
end
|
.find_by_uuid(uuid) ⇒ Object
29
30
31
|
# File 'lib/pact_broker/webhooks/service.rb', line 29
def self.find_by_uuid uuid
webhook_repository.find_by_uuid uuid
end
|
.next_uuid ⇒ Object
15
16
17
|
# File 'lib/pact_broker/webhooks/service.rb', line 15
def self.next_uuid
SecureRandom.urlsafe_base64
end
|
.run_later(webhooks) ⇒ Object
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/pact_broker/webhooks/service.rb', line 66
def self.run_later webhooks
webhooks.each do | webhook |
begin
logger.info "Scheduling job for #{webhook.description} with uuid #{webhook.uuid}"
Job.perform_async webhook: webhook
rescue StandardError => e
log_error e
end
end
end
|