@rivetkit/workflow-engine 2.3.0-rc.4 → 2.3.0-rc.5
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.
- package/dist/tsup/{chunk-UMFB2AR3.js → chunk-CIDHCIH7.js} +48 -15
- package/dist/tsup/chunk-CIDHCIH7.js.map +1 -0
- package/dist/tsup/{chunk-4SWXLWKL.cjs → chunk-SFJQFMCW.cjs} +48 -15
- package/dist/tsup/chunk-SFJQFMCW.cjs.map +1 -0
- package/dist/tsup/index.cjs +2 -2
- package/dist/tsup/index.d.cts +6 -0
- package/dist/tsup/index.d.ts +6 -0
- package/dist/tsup/index.js +1 -1
- package/dist/tsup/testing.cjs +23 -23
- package/dist/tsup/testing.js +1 -1
- package/package.json +1 -1
- package/src/context.ts +12 -11
- package/src/storage.ts +50 -3
- package/src/types.ts +7 -5
- package/dist/tsup/chunk-4SWXLWKL.cjs.map +0 -1
- package/dist/tsup/chunk-UMFB2AR3.js.map +0 -1
|
@@ -1402,6 +1402,8 @@ function deserializeName(bytes) {
|
|
|
1402
1402
|
}
|
|
1403
1403
|
|
|
1404
1404
|
// src/storage.ts
|
|
1405
|
+
var MAX_KV_BATCH_ENTRIES = 128;
|
|
1406
|
+
var MAX_KV_BATCH_PAYLOAD_BYTES = 976 * 1024;
|
|
1405
1407
|
function createStorage() {
|
|
1406
1408
|
return {
|
|
1407
1409
|
nameRegistry: [],
|
|
@@ -1519,6 +1521,8 @@ async function loadMetadata(storage, driver, entryId) {
|
|
|
1519
1521
|
}
|
|
1520
1522
|
async function flush(storage, driver, onHistoryUpdated, pendingDeletions) {
|
|
1521
1523
|
const writes = [];
|
|
1524
|
+
const dirtyEntries = [];
|
|
1525
|
+
const dirtyMetadata = [];
|
|
1522
1526
|
let historyUpdated = false;
|
|
1523
1527
|
for (let i = storage.flushedNameCount; i < storage.nameRegistry.length; i++) {
|
|
1524
1528
|
const name = storage.nameRegistry[i];
|
|
@@ -1536,7 +1540,7 @@ async function flush(storage, driver, onHistoryUpdated, pendingDeletions) {
|
|
|
1536
1540
|
key: buildHistoryKey(entry.location),
|
|
1537
1541
|
value: serializeEntry(entry)
|
|
1538
1542
|
});
|
|
1539
|
-
entry
|
|
1543
|
+
dirtyEntries.push(entry);
|
|
1540
1544
|
historyUpdated = true;
|
|
1541
1545
|
}
|
|
1542
1546
|
}
|
|
@@ -1546,7 +1550,7 @@ async function flush(storage, driver, onHistoryUpdated, pendingDeletions) {
|
|
|
1546
1550
|
key: buildEntryMetadataKey(id),
|
|
1547
1551
|
value: serializeEntryMetadata(metadata)
|
|
1548
1552
|
});
|
|
1549
|
-
metadata
|
|
1553
|
+
dirtyMetadata.push(metadata);
|
|
1550
1554
|
historyUpdated = true;
|
|
1551
1555
|
}
|
|
1552
1556
|
}
|
|
@@ -1570,7 +1574,9 @@ async function flush(storage, driver, onHistoryUpdated, pendingDeletions) {
|
|
|
1570
1574
|
});
|
|
1571
1575
|
}
|
|
1572
1576
|
if (writes.length > 0) {
|
|
1573
|
-
|
|
1577
|
+
for (const chunk of splitBatchWrites(writes)) {
|
|
1578
|
+
await driver.batch(chunk);
|
|
1579
|
+
}
|
|
1574
1580
|
}
|
|
1575
1581
|
if (pendingDeletions) {
|
|
1576
1582
|
const deleteOps = [];
|
|
@@ -1588,6 +1594,12 @@ async function flush(storage, driver, onHistoryUpdated, pendingDeletions) {
|
|
|
1588
1594
|
historyUpdated = true;
|
|
1589
1595
|
}
|
|
1590
1596
|
}
|
|
1597
|
+
for (const entry of dirtyEntries) {
|
|
1598
|
+
entry.dirty = false;
|
|
1599
|
+
}
|
|
1600
|
+
for (const metadata of dirtyMetadata) {
|
|
1601
|
+
metadata.dirty = false;
|
|
1602
|
+
}
|
|
1591
1603
|
storage.flushedNameCount = storage.nameRegistry.length;
|
|
1592
1604
|
storage.flushedState = storage.state;
|
|
1593
1605
|
storage.flushedOutput = storage.output;
|
|
@@ -1596,6 +1608,30 @@ async function flush(storage, driver, onHistoryUpdated, pendingDeletions) {
|
|
|
1596
1608
|
onHistoryUpdated();
|
|
1597
1609
|
}
|
|
1598
1610
|
}
|
|
1611
|
+
function splitBatchWrites(writes) {
|
|
1612
|
+
const chunks = [];
|
|
1613
|
+
let chunk = [];
|
|
1614
|
+
let chunkBytes = 0;
|
|
1615
|
+
for (const write of writes) {
|
|
1616
|
+
const writeBytes = write.key.byteLength + write.value.byteLength;
|
|
1617
|
+
if (writeBytes > MAX_KV_BATCH_PAYLOAD_BYTES) {
|
|
1618
|
+
throw new Error(
|
|
1619
|
+
`KV batch write is ${writeBytes} bytes, exceeding the ${MAX_KV_BATCH_PAYLOAD_BYTES} byte limit`
|
|
1620
|
+
);
|
|
1621
|
+
}
|
|
1622
|
+
if (chunk.length >= MAX_KV_BATCH_ENTRIES || chunk.length > 0 && chunkBytes + writeBytes > MAX_KV_BATCH_PAYLOAD_BYTES) {
|
|
1623
|
+
chunks.push(chunk);
|
|
1624
|
+
chunk = [];
|
|
1625
|
+
chunkBytes = 0;
|
|
1626
|
+
}
|
|
1627
|
+
chunk.push(write);
|
|
1628
|
+
chunkBytes += writeBytes;
|
|
1629
|
+
}
|
|
1630
|
+
if (chunk.length > 0) {
|
|
1631
|
+
chunks.push(chunk);
|
|
1632
|
+
}
|
|
1633
|
+
return chunks;
|
|
1634
|
+
}
|
|
1599
1635
|
async function deleteEntriesWithPrefix(storage, driver, prefixLocation, onHistoryUpdated) {
|
|
1600
1636
|
const deletions = collectDeletionsForPrefix(storage, prefixLocation);
|
|
1601
1637
|
await driver.deletePrefix(deletions.prefixes[0]);
|
|
@@ -2266,15 +2302,12 @@ var WorkflowContextImpl = (_class = class _WorkflowContextImpl {
|
|
|
2266
2302
|
willRetry: false
|
|
2267
2303
|
});
|
|
2268
2304
|
throw markErrorReported(
|
|
2269
|
-
attachTryStepFailure(
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
error: extractErrorInfo(error)
|
|
2276
|
-
}
|
|
2277
|
-
)
|
|
2305
|
+
attachTryStepFailure(new CriticalError(error.message), {
|
|
2306
|
+
kind: "timeout",
|
|
2307
|
+
stepName: config2.name,
|
|
2308
|
+
attempts: metadata.attempts,
|
|
2309
|
+
error: extractErrorInfo(error)
|
|
2310
|
+
})
|
|
2278
2311
|
);
|
|
2279
2312
|
}
|
|
2280
2313
|
if (error instanceof CriticalError || error instanceof RollbackError) {
|
|
@@ -2481,8 +2514,8 @@ var WorkflowContextImpl = (_class = class _WorkflowContextImpl {
|
|
|
2481
2514
|
metadata.error = void 0;
|
|
2482
2515
|
metadata.dirty = true;
|
|
2483
2516
|
}
|
|
2484
|
-
const historyPruneInterval = _nullishCoalesce(config2.historyPruneInterval, () => ( DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL));
|
|
2485
|
-
const historySize = _nullishCoalesce(config2.historySize, () => ( historyPruneInterval));
|
|
2517
|
+
const historyPruneInterval = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(config2.historyPruneInterval, () => ( config2.commitInterval)), () => ( config2.historyEvery)), () => ( DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL));
|
|
2518
|
+
const historySize = _nullishCoalesce(_nullishCoalesce(config2.historySize, () => ( config2.historyKeep)), () => ( historyPruneInterval));
|
|
2486
2519
|
let lastPrunedUpTo = 0;
|
|
2487
2520
|
let deferredFlush = null;
|
|
2488
2521
|
while (true) {
|
|
@@ -4177,4 +4210,4 @@ async function executeWorkflow(workflowId, workflowFn, input, driver, messageDri
|
|
|
4177
4210
|
|
|
4178
4211
|
|
|
4179
4212
|
exports.extractErrorInfo = extractErrorInfo; exports.CriticalError = CriticalError; exports.RollbackError = RollbackError; exports.RollbackCheckpointError = RollbackCheckpointError; exports.SleepError = SleepError; exports.MessageWaitError = MessageWaitError; exports.EvictedError = EvictedError; exports.HistoryDivergedError = HistoryDivergedError; exports.StepExhaustedError = StepExhaustedError; exports.StepFailedError = StepFailedError; exports.JoinError = JoinError; exports.RaceError = RaceError; exports.CancelledError = CancelledError; exports.EntryInProgressError = EntryInProgressError; exports.keyStartsWith = keyStartsWith; exports.compareKeys = compareKeys; exports.keyToHex = keyToHex; exports.isLoopIterationMarker = isLoopIterationMarker; exports.registerName = registerName; exports.resolveName = resolveName; exports.locationToKey = locationToKey; exports.appendName = appendName; exports.appendLoopIteration = appendLoopIteration; exports.emptyLocation = emptyLocation; exports.parentLocation = parentLocation; exports.isLocationPrefix = isLocationPrefix; exports.locationsEqual = locationsEqual; exports.createStorage = createStorage; exports.createHistorySnapshot = createHistorySnapshot; exports.generateId = generateId; exports.createEntry = createEntry; exports.getOrCreateMetadata = getOrCreateMetadata; exports.loadStorage = loadStorage; exports.loadMetadata = loadMetadata; exports.flush = flush; exports.deleteEntriesWithPrefix = deleteEntriesWithPrefix; exports.getEntry = getEntry; exports.setEntry = setEntry; exports.sleep = sleep; exports.DEFAULT_MAX_RETRIES = DEFAULT_MAX_RETRIES; exports.DEFAULT_RETRY_BACKOFF_BASE = DEFAULT_RETRY_BACKOFF_BASE; exports.DEFAULT_RETRY_BACKOFF_MAX = DEFAULT_RETRY_BACKOFF_MAX; exports.DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL = DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL; exports.DEFAULT_STEP_TIMEOUT = DEFAULT_STEP_TIMEOUT; exports.WorkflowContextImpl = WorkflowContextImpl; exports.Loop = Loop; exports.runWorkflow = runWorkflow; exports.replayWorkflowFromStep = replayWorkflowFromStep;
|
|
4180
|
-
//# sourceMappingURL=chunk-
|
|
4213
|
+
//# sourceMappingURL=chunk-SFJQFMCW.cjs.map
|