Skip to content
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(transaction): support run after transaction functionality #2742

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

roggervalf
Copy link
Contributor

@roggervalf roggervalf commented Feb 17, 2025

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.

return Promise.reject(new Error('Run After transaction failed.'));
});
}
if ((index + 1) % afterTransactionMethodsBatch === 0) {
Copy link
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

@roggervalf
Copy link
Contributor Author

Pls @lehni when you get some time

@@ -526,7 +528,22 @@ class Model {
knexOrTrx = null;
}

return (knexOrTrx || this.knex()).transaction(cb);
return (knexOrTrx || this.knex()).transaction((trx) => {
trx.runAfterTransactionMethods = [];
Copy link
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.

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