-
Notifications
You must be signed in to change notification settings - Fork 89
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
feat(backend): manage webhook event lifecycle in webhook service #228
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6c97ba2
feat(backend): manage webhook event lifecycle in webhook service
wilsonianb aa68573
chore(backend): add invoice and payment webhook event models
wilsonianb e964ca8
chore(backend): add onCredit/onDebit to LiquidityAccount
wilsonianb 3075f08
chore(backend): update transaction api docs
wilsonianb cdee2bb
chore(backend): update transaction api docs
wilsonianb 1786e7d
chore(backend): create withdrawal in webhook service
wilsonianb e47695c
chore(backend): specify webhook event withdrawals
wilsonianb 07661cf
chore(backend): only call onCredit for destinationAccount
wilsonianb 5f1fbbd
chore(backend): require 200 webhook response
wilsonianb 42d82ea
fix(backend): don't update event amount after processAt
wilsonianb c13231a
chore(backend): do single-phase withdrawal in withdrawEventLiquidity
wilsonianb 9ac5b15
chore(backend): create one webhook event per invoice
wilsonianb f5a2ae9
chore(backend): remove retry and retention event limits
wilsonianb 1cc89ce
chore(backend): verify event deposit is created
wilsonianb 5757cbb
chore(backend): make timeouts in milliseconds
wilsonianb 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 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 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 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
26 changes: 26 additions & 0 deletions
26
packages/backend/migrations/20220131110501_create_webhook_events_table.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
exports.up = function (knex) { | ||
return knex.schema.createTable('webhookEvents', function (table) { | ||
table.uuid('id').notNullable().primary() | ||
|
||
table.string('type').notNullable() | ||
table.json('data').notNullable() | ||
table.integer('attempts').notNullable().defaultTo(0) | ||
table.integer('statusCode').nullable() | ||
|
||
table.uuid('withdrawalAccountId').nullable() | ||
table.uuid('withdrawalAssetId').nullable() | ||
table.foreign('withdrawalAssetId').references('assets.id') | ||
table.bigInteger('withdrawalAmount').nullable() | ||
|
||
table.timestamp('processAt').nullable().defaultTo(knex.fn.now()) | ||
|
||
table.timestamp('createdAt').defaultTo(knex.fn.now()) | ||
table.timestamp('updatedAt').defaultTo(knex.fn.now()) | ||
|
||
table.index('processAt') | ||
}) | ||
} | ||
|
||
exports.down = function (knex) { | ||
return knex.schema.dropTableIfExists('webhookEvents') | ||
} |
This file contains 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 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 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 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 |
---|---|---|
|
@@ -143,6 +143,9 @@ export class App { | |
for (let i = 0; i < this.config.invoiceWorkers; i++) { | ||
process.nextTick(() => this.processInvoice()) | ||
} | ||
for (let i = 0; i < this.config.webhookWorkers; i++) { | ||
process.nextTick(() => this.processWebhook()) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -288,4 +291,22 @@ export class App { | |
).unref() | ||
}) | ||
} | ||
|
||
private async processWebhook(): Promise<void> { | ||
const webhookService = await this.container.use('webhookService') | ||
return webhookService | ||
.processNext() | ||
.catch((err) => { | ||
this.logger.warn({ error: err.message }, 'processWebhook error') | ||
return true | ||
}) | ||
Comment on lines
+299
to
+302
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a single one fails, does this whole process crash? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think returning true in the |
||
.then((hasMoreWork) => { | ||
if (hasMoreWork) process.nextTick(() => this.processWebhook()) | ||
else | ||
setTimeout( | ||
() => this.processWebhook(), | ||
this.config.webhookWorkerIdle | ||
).unref() | ||
}) | ||
} | ||
} |
This file contains 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 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 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (and other)
timeout
parameters should be named with the unit; e.g.timeoutNano
,timeoutMilli
.JS timeouts are typically milliseconds (e.g.
setTimeout
) but TigerBeetle uses nanoseconds. Since we need to use both (in different contexts), I think its worth disambiguating them in the property name so that there's no confusion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we kept the name
timeout
but keep it consistent as milliseconds and convert to nano-seconds where passing to tigerbeetle-node?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 That works.