-
-
Notifications
You must be signed in to change notification settings - Fork 89
Add webhook circuit breaker #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ViperTecCorporation
wants to merge
10
commits into
clairton:main
Choose a base branch
from
ViperTecCorporation:feature/webhook-circuit-breaker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
07e28f7
Add webhook circuit breaker
ViperTecCorporation 8108788
Document circuit breaker behavior and set timeout default to 60s
ViperTecCorporation 4f712f6
Requeue on webhook circuit breaker open
ViperTecCorporation 022e68c
Lower consumer timeout default to 15s
ViperTecCorporation df6957d
Add periodic cleanup for local CB state
ViperTecCorporation 7602d5d
Add env for local CB cleanup interval
ViperTecCorporation f4edfc0
Fix CB open check and add cleanup env
ViperTecCorporation a6e13db
Fix duplicate key in README example
ViperTecCorporation 77b01ca
Log original error when CB handler fails
ViperTecCorporation 82a6f8c
Fix webhook CB error handling
ViperTecCorporation File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -435,7 +435,7 @@ Create a `.env`file and put configuration if you need change default value: | |
| This a general env: | ||
|
|
||
| ```env | ||
| CONSUMER_TIMEOUT_MS=miliseconds in timeout for consume job, default is 30000 | ||
| CONSUMER_TIMEOUT_MS=miliseconds in timeout for consume job, default is 15000 | ||
| AVAILABLE_LOCALES=default is `["en", "pt_BR", "pt"]` | ||
| DEFAULT_LOCALE=locale for notifications status, now possibile is en, pt_BR and pt, default is en, to add new, use docker volume for exempla `/app/dist/src/locales/custom.json` and add `custom` in `AVAILABLE_LOCALES` | ||
| ONLY_HELLO_TEMPLATE=true sets hello template as the only default template, default false. | ||
|
|
@@ -487,7 +487,13 @@ WEBHOOK_URL_ABSOLUTE=the webhook absolute url, not use this if already use WEBHO | |
| WEBHOOK_URL=the webhook url, this config attribute put phone number on the end, no use if use WEBHOOK_URL_ABSOLUTE | ||
| WEBHOOK_TOKEN=the webhook header token | ||
| WEBHOOK_HEADER=the webhook header name | ||
| WEBHOOK_TIMEOUT_MS=webhook request timeout, default 5000 ms | ||
| WEBHOOK_TIMEOUT_MS=webhook request timeout, default 60000 ms | ||
| WEBHOOK_CB_ENABLED=true enable webhook circuit breaker to avoid backlog when endpoint is offline, default true | ||
| WEBHOOK_CB_FAILURE_THRESHOLD=number of failures within window to open circuit, default 1 | ||
| WEBHOOK_CB_OPEN_MS=how long to keep the circuit open (skip sends), default 120000 | ||
| WEBHOOK_CB_FAILURE_TTL_MS=failure counter window in ms, default 300000 | ||
| WEBHOOK_CB_REQUEUE_DELAY_MS=delay (ms) used to requeue when circuit is open, default 300000 | ||
| WEBHOOK_CB_LOCAL_CLEANUP_INTERVAL_MS=local CB map cleanup interval (ms), default 3600000 | ||
| WEBHOOK_SEND_NEW_MESSAGES=true, send new messages to webhook, caution with this, messages will be duplicated, default is false | ||
| WEBHOOK_SEND_GROUP_MESSAGES=true, send group messages to webhook, default is true | ||
| WEBHOOK_SEND_OUTGOING_MESSAGES=true, send outgoing messages to webhook, default is true | ||
|
|
@@ -521,7 +527,27 @@ WEBHOOK_FORWARD_BUSINESS_ACCOUNT_ID=the business account id of whatsapp cloud ap | |
| WEBHOOK_FORWARD_TOKEN=the token of whatsapp cloud api, default is empty | ||
| WEBHOOK_FORWARD_VERSION=the version of whatsapp cloud api, default is v17.0 | ||
| WEBHOOK_FORWARD_URL=the url of whatsapp cloud api, default is https://graph.facebook.com | ||
| WEBHOOK_FORWARD_TIMEOUT_MS=the timeout for request to whatsapp cloud api, default is 360000 | ||
| WEBHOOK_FORWARD_TIMEOUT_MS=the timeout for request to whatsapp cloud api, default is 60000 | ||
| ``` | ||
| Circuit breaker behavior: | ||
| - Counts consecutive webhook failures within `WEBHOOK_CB_FAILURE_TTL_MS`. | ||
| - When the count reaches `WEBHOOK_CB_FAILURE_THRESHOLD`, the circuit opens for `WEBHOOK_CB_OPEN_MS` and sends are skipped. | ||
| - After the open window, delivery is attempted again automatically. | ||
| - When the circuit is open, the message is requeued with a longer delay (`WEBHOOK_CB_REQUEUE_DELAY_MS`) to avoid retry storms. | ||
|
|
||
| Why keep `WEBHOOK_TIMEOUT_MS` low: | ||
| - A high timeout blocks the consumer for too long when the endpoint is offline. | ||
| - With lower timeout, failures are detected faster and the circuit opens sooner, reducing backlog. | ||
|
|
||
| Example (circuit breaker): | ||
| ```env | ||
| WEBHOOK_CB_ENABLED=true | ||
| WEBHOOK_CB_FAILURE_THRESHOLD=1 | ||
| WEBHOOK_CB_FAILURE_TTL_MS=300000 | ||
| WEBHOOK_CB_OPEN_MS=120000 | ||
| WEBHOOK_CB_REQUEUE_DELAY_MS=300000 | ||
| WEBHOOK_CB_LOCAL_CLEANUP_INTERVAL_MS=3600000 | ||
| WEBHOOK_TIMEOUT_MS=60000 | ||
| ``` | ||
|
|
||
| ### Config session with redis | ||
|
|
@@ -808,4 +834,5 @@ Mail to [email protected] | |
| - Connect with pairing code: https://github.com/WhiskeySockets/Baileys#starting-socket-with-pairing-code | ||
| - Counting connection retry attempts even when restarting to prevent looping messages | ||
| - Message delete endpoint | ||
| - Send reply message with please to send again, when any error and message enqueue in .dead | ||
| - Send reply message with please to send again, when any error and message enqueue in .dead | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.