@moinulmoin/eden-world-cloudflare 0.11.1 → 0.11.3

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.
@@ -45,6 +45,7 @@ export declare class WorldCore {
45
45
  private readonly waitUntil;
46
46
  private readonly retireDeployment;
47
47
  private readonly currentDeploymentId;
48
+ private readonly isDeploymentRemoved;
48
49
  constructor(opts: {
49
50
  sql: SqlExec;
50
51
  delivery: QueueDelivery;
@@ -53,6 +54,7 @@ export declare class WorldCore {
53
54
  waitUntil?: (promise: Promise<void>) => void;
54
55
  retireDeployment?: (deploymentId: string) => Promise<void>;
55
56
  currentDeploymentId?: string;
57
+ isDeploymentRemoved?: (deploymentId: string) => boolean;
56
58
  });
57
59
  private rows;
58
60
  private atomic;
@@ -43,6 +43,7 @@ export class WorldCore {
43
43
  waitUntil;
44
44
  retireDeployment;
45
45
  currentDeploymentId;
46
+ isDeploymentRemoved;
46
47
  constructor(opts) {
47
48
  this.sql = opts.sql;
48
49
  this.delivery = opts.delivery;
@@ -51,6 +52,7 @@ export class WorldCore {
51
52
  this.waitUntil = opts.waitUntil ?? (() => { });
52
53
  this.retireDeployment = opts.retireDeployment;
53
54
  this.currentDeploymentId = opts.currentDeploymentId;
55
+ this.isDeploymentRemoved = opts.isDeploymentRemoved;
54
56
  }
55
57
  rows(query, ...args) { return this.sql.exec(query, ...args).toArray(); }
56
58
  atomic(fn) { return this.sql.transactionSync ? this.sql.transactionSync(fn) : fn(); }
@@ -116,8 +118,8 @@ export class WorldCore {
116
118
  run(id) { const value = unpack(this.rows('SELECT data FROM workflow_runs WHERE id = ?', id)[0]); if (!value)
117
119
  throw new WorkflowRunNotFoundError(id); return WorkflowRunSchema.parse(value); }
118
120
  assertDeploymentActive(deploymentId) {
119
- if (this.rows('SELECT deployment_id FROM workflow_retired_deployments WHERE deployment_id=?', deploymentId).length)
120
- throw new WorkflowWorldError(`Deployment ${deploymentId} has been retired`, { status: 409 });
121
+ if (this.isDeploymentRemoved?.(deploymentId) || this.rows('SELECT deployment_id FROM workflow_retired_deployments WHERE deployment_id=?', deploymentId).length)
122
+ throw new WorkflowWorldError(`Deployment ${deploymentId} has been retired; its sessions ended. Start a new session.`, { status: 409 });
121
123
  }
122
124
  deliverySettled(messageId, attempt) {
123
125
  // Called by the receiving Container DO through the current World actor.
@@ -922,11 +924,23 @@ export class WorldCore {
922
924
  const body = sqlBytes(row.body);
923
925
  const message = this.queueMessage(body);
924
926
  const deploymentId = this.queueTarget(message, row.deployment_id == null ? undefined : String(row.deployment_id));
925
- this.assertDeploymentActive(deploymentId);
926
- this.sql.exec('UPDATE workflow_queue_messages SET deployment_id=? WHERE id=?', deploymentId, id);
927
927
  let transfer = this.rows('SELECT * FROM workflow_sandbox_transfers WHERE message_id=?', id)[0];
928
928
  const sandbox = transfer ? undefined : this.successorSandbox(message);
929
- const sourceDeploymentId = transfer ? String(transfer.source_deployment_id) : sandbox?.sourceDeploymentId ?? (row.source_deployment_id == null ? undefined : String(row.source_deployment_id));
929
+ const source = transfer ? String(transfer.source_deployment_id) : sandbox?.sourceDeploymentId ?? (row.source_deployment_id == null ? undefined : String(row.source_deployment_id));
930
+ if (this.isDeploymentRemoved?.(deploymentId) || (source && this.isDeploymentRemoved?.(source)) ||
931
+ this.rows('SELECT deployment_id FROM workflow_retired_deployments WHERE deployment_id=? OR deployment_id=?', deploymentId, source ?? deploymentId).length) {
932
+ // A removed deployment cannot ever accept this delivery again.
933
+ // Preserve run history, but settle the message instead of retrying.
934
+ this.atomic(() => {
935
+ this.sql.exec('UPDATE workflow_sandbox_transfers SET completed=-1 WHERE message_id=? AND completed=0', id);
936
+ this.deliverySettled(id, attempt);
937
+ this.sql.exec('UPDATE workflow_queue_messages SET completed=1,idempotency_key=NULL,lease_until=0 WHERE id=?', id);
938
+ });
939
+ return;
940
+ }
941
+ this.assertDeploymentActive(deploymentId);
942
+ this.sql.exec('UPDATE workflow_queue_messages SET deployment_id=? WHERE id=?', deploymentId, id);
943
+ const sourceDeploymentId = source;
930
944
  if (sandbox && sourceDeploymentId && sourceDeploymentId !== deploymentId) {
931
945
  this.assertDeploymentActive(sourceDeploymentId);
932
946
  this.sql.exec('UPDATE workflow_queue_messages SET source_deployment_id=? WHERE id=?', sourceDeploymentId, id);
@@ -1002,7 +1016,7 @@ export class WorldCore {
1002
1016
  if (this.currentDeploymentId && ids.includes(this.currentDeploymentId))
1003
1017
  throw new WorkflowWorldError('Cannot retire the current deployment', { status: 409 });
1004
1018
  const states = this.drainState(ids);
1005
- if (ids.some(id => !states[id].drained))
1019
+ if (ids.some(id => !this.isDeploymentRemoved?.(id) && !states[id].drained))
1006
1020
  throw new WorkflowWorldError('Cannot retire a deployment with live runs, queued messages, or unfinished transfers', { status: 409 });
1007
1021
  if (!this.retireDeployment)
1008
1022
  throw new WorkflowWorldError('Deployment retirement is unavailable', { status: 501 });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moinulmoin/eden-world-cloudflare",
3
- "version": "0.11.1",
3
+ "version": "0.11.3",
4
4
  "description": "Cloudflare Durable Object SQLite World for Eve workflows.",
5
5
  "eden": {
6
6
  "capabilities": {