Skip to content

feat(transaction): support run after transaction functionality#2742

Open
roggervalf wants to merge 2 commits into
Vincit:mainfrom
roggervalf:run-after-transaction
Open

feat(transaction): support run after transaction functionality#2742
roggervalf wants to merge 2 commits into
Vincit:mainfrom
roggervalf:run-after-transaction

Conversation

@roggervalf

@roggervalf roggervalf commented Feb 17, 2025

Copy link
Copy Markdown
Contributor

same as in #2582, where runAfterTransactionMethods is a collector of all methods to be executed after transaction is committed. All these methods are executed and only if at least 1 of them fail, an error is thrown.

Comment thread lib/transaction.js
return Promise.reject(new Error('Run After transaction failed.'));
});
}
if ((index + 1) % afterTransactionMethodsBatch === 0) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as there could be many methods to be executed after transaction, better to do this operation in batches. In order to prevent thousands of promises in parallel that consume more resources that are available

Comment thread lib/model/Model.js

return (knexOrTrx || this.knex()).transaction(cb);
return (knexOrTrx || this.knex()).transaction((trx) => {
trx.runAfterTransactionMethods = [];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extending trx object to save runAfterTransactionMethods and afterTransationMethodsBatch helpers.

@roggervalf

Copy link
Copy Markdown
Contributor Author

Pls @lehni when you get some time. What do you think about this approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant