@effect-agent/storage-cloudflare 0.1.0-beta.97 → 0.1.0-beta.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -296,8 +296,8 @@ const makeServices = Effect.fn("DoSubmissionLedger.makeServices")(function* () {
|
|
|
296
296
|
*/
|
|
297
297
|
const requireOwnership = Effect.fn("DoSubmissionLedger.requireOwnership")(function* (operation, submission, ownershipToken) {
|
|
298
298
|
const ownership = yield* readOwnership(operation, submission.submission_id);
|
|
299
|
-
|
|
300
|
-
|
|
299
|
+
const actualEpoch = yield* threadEpoch(operation, submission.thread_id);
|
|
300
|
+
if (Option.isNone(ownership) || ownership.value.ownership_token !== ownershipToken || ownership.value.producer_epoch !== actualEpoch) {
|
|
301
301
|
const submissionId = yield* Schema.decodeEffect(SubmissionSnapshot.fields.submissionId)(submission.submission_id).pipe(Effect.mapError(internalFailure(operation)));
|
|
302
302
|
return yield* OwnershipLost.make({
|
|
303
303
|
submissionId,
|
|
@@ -722,11 +722,31 @@ const makeServices = Effect.fn("DoSubmissionLedger.makeServices")(function* () {
|
|
|
722
722
|
const ownershipToken = `owner-${yield* mintUuid(operation)}`;
|
|
723
723
|
yield* hitFailpoint("ledger:claim:before", operation);
|
|
724
724
|
const claimed = yield* inWriteTransaction(operation, Effect.gen(function* () {
|
|
725
|
+
const now = yield* currentInstant;
|
|
726
|
+
const ownershipRows = yield* sql`
|
|
727
|
+
SELECT ownership.*
|
|
728
|
+
FROM effect_agent_submission_ownership AS ownership
|
|
729
|
+
JOIN effect_agent_submissions AS submission
|
|
730
|
+
ON submission.submission_id = ownership.submission_id
|
|
731
|
+
WHERE submission.thread_id = ${validated.threadId}
|
|
732
|
+
ORDER BY ownership.lease_expires_at DESC
|
|
733
|
+
LIMIT 1
|
|
734
|
+
`.pipe(Effect.mapError(sqlFailure(operation)));
|
|
735
|
+
const ownership = yield* decodeRows(Schema.Array(OwnershipRow), "effect_agent_submission_ownership", validated.threadId, ownershipRows).pipe(Effect.mapError(internalFailure(operation)));
|
|
736
|
+
if (ownership.length > 0) {
|
|
737
|
+
if ((yield* timestampMillis(operation, ownership[0].submission_id)(ownership[0].lease_expires_at)) > now.millis) return Option.none();
|
|
738
|
+
}
|
|
725
739
|
const headRows = yield* sql`
|
|
726
740
|
SELECT ${sql.literal(SUBMISSION_COLUMNS)}
|
|
727
741
|
FROM effect_agent_submissions
|
|
728
742
|
WHERE thread_id = ${validated.threadId}
|
|
729
743
|
AND state <> 'settled'
|
|
744
|
+
AND (
|
|
745
|
+
state <> 'unknown' OR EXISTS (
|
|
746
|
+
SELECT 1 FROM effect_agent_abort_intents
|
|
747
|
+
WHERE submission_id = effect_agent_submissions.submission_id
|
|
748
|
+
)
|
|
749
|
+
)
|
|
730
750
|
ORDER BY queue_sequence ASC
|
|
731
751
|
LIMIT 1
|
|
732
752
|
`.pipe(Effect.mapError(sqlFailure(operation)));
|
|
@@ -734,11 +754,6 @@ const makeServices = Effect.fn("DoSubmissionLedger.makeServices")(function* () {
|
|
|
734
754
|
if (heads.length === 0) return Option.none();
|
|
735
755
|
const head = heads[0];
|
|
736
756
|
if (head.state === "joining" || head.state === "joined" || head.state === "suspended" || head.state === "unknown" && Option.isNone(yield* readAbortIntent(operation, head.submission_id))) return Option.none();
|
|
737
|
-
const now = yield* currentInstant;
|
|
738
|
-
const ownership = yield* readOwnership(operation, head.submission_id);
|
|
739
|
-
if (Option.isSome(ownership)) {
|
|
740
|
-
if ((yield* timestampMillis(operation, head.submission_id)(ownership.value.lease_expires_at)) > now.millis) return Option.none();
|
|
741
|
-
}
|
|
742
757
|
const threads = yield* journal.getThread(head.thread_id).pipe(Effect.mapError(internalFailure(operation)));
|
|
743
758
|
let producerEpoch;
|
|
744
759
|
if (threads.length === 0) {
|