Repository navigation
feat(database): afterCommit runs work after the outermost COMMIT - #100
Merged
Merged
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 51 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Effect 4.0.6 ships SqlClient.afterCommit with the same queueing rules: after the outermost COMMIT, dropped on rollback, a kept savepoint hands its callbacks to its parent, and a defect after the transaction ended. Db.afterCommit now delegates to it and keeps only what Effect lacks: Transaction in R, and a failing hook reported to ErrorReporter and the log instead of failing the committed transaction. The hook queue on OpenState, runHooks and AfterCommitUnavailable go. A plain sql.withTransaction as the outer transaction now runs the hooks instead of dying, since Effect queues them there too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Thanks for this. Since #125 bumped us to Effect 4.0.6, which ships
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A vendor call (SMS, HTTP, job enqueue) must not run inside a transaction, and today each call site must wait for COMMIT by hand. This PR adds
Db.afterCommit(effect): the effect runs only after the outermost transaction commits, and never after a rollback.Closes #73.
Part of #52.
Changes
Db.afterCommit(effect)in/database. LikerequireTransaction, it addsTransactiontoR. The requirements of the queued effect stay inR.transactionlevel keeps a queue on its private open-state service. The outermost level runs its queue after COMMIT, in queue order, one hook at a time, outside the transaction's span (in aneffect_orm.after_commitspan).retry, only the attempt that commits runs its hooks.sql.transactionService, the open state,Transaction) are replaced with the ones outside the transaction, so a statement in a hook uses its own connection.ErrorReporter.report(the reporters in context) and toEffect.logError, with the hook index as a log annotation. The next hook still runs. A caller that must know handles the error in the hook.AfterCommitUnavailable, when nothing would run the work: aTransactionprovided by hand, a transaction that has ended (an unjoined fork), or an outermost transaction opened by a plainsql.withTransaction. The work is never dropped without a sign.src/database/after-commit.test.ts(PGlite, 6 tests) and type tests insrc/database/database.test-d.ts.docs/database.md,docs/reference.md, section 10 indesign/transactions.md. Oneminorchangeset.Left out
transaction, so a later dialect gets it without change. D1batch()(D1batch()as a typed atomic unit #55) is not covered.sql.withTransactioninside aDb.transactiondo not drop hooks when they roll back. The docs say to nest withDb.transaction.Validation
bun run build: pass.bun run typecheck: pass.bunx vitest run --testTimeout=60000 --hookTimeout=60000with a live ClickHouse 26.8.2.7 (EFFECT_ORM_CLICKHOUSE_*set): 61 files passed, 1040 tests passed, 0 skipped.node scripts/check-doc-citations.mjs,node scripts/check-exports-documented.mjs,node scripts/check-doc-examples.mjs: pass.bun scripts/check-package.ts: pass.Need help on this PR? Tag
@codesmith-botwith what you need.