Skip to content

Commit f0d6be8

Browse files
committed
update webhook worker to auto-disable frozen endpoints
1 parent ab4da45 commit f0d6be8

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

app/workers/webhook_worker.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ def perform(account_id, event_id, endpoint_id, event_data)
155155
event.update!(status: 'FAILED')
156156
endpoint.disable!
157157

158+
return
159+
in last_response_code: 530
160+
Keygen.logger.warn "[webhook_worker] Disabling Frozen endpoint: type=#{event_type.event} account=#{account.id} event=#{event.id} endpoint=#{endpoint.id} url=#{endpoint.url} code=#{res.code}"
161+
162+
# Automatically disable endpoints returning 530 Frozen
163+
event.update!(status: 'FAILED')
164+
endpoint.disable!
165+
158166
return
159167
else
160168
Keygen.logger.warn "[webhook_worker] Failed webhook event: type=#{event_type.event} account=#{account.id} event=#{event.id} endpoint=#{endpoint.id} url=#{endpoint.url} code=#{res.code}"

spec/services/broadcast_event_service_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,21 @@ def jsonapi_render(resource, account:, meta: nil, **options)
249249
expect(endpoint.subscriptions).to be_empty
250250
end
251251

252+
it 'should disable endpoint when status is 530 Frozen' do
253+
allow(WebhookWorker::Request).to receive(:post) {
254+
OpenStruct.new(code: 530, body: '530 Frozen')
255+
}
256+
257+
event = nil
258+
expect { event = create_webhook_event!(account, resource) }.to_not raise_error
259+
expect(event).to_not be_nil
260+
expect(event.last_response_body).to eq '530 Frozen'
261+
expect(event.last_response_code).to eq 530
262+
263+
expect { endpoint.reload }.to_not raise_error
264+
expect(endpoint.subscriptions).to be_empty
265+
end
266+
252267
context 'when endpoint has an environment' do
253268
before do
254269
create_list(:webhook_endpoint, 5, :in_isolated_environment, account:)

0 commit comments

Comments
 (0)