Skip to content

Commit f31397c

Browse files
authored
fix: dequeue items in DB after each task is complete (#354)
1 parent f6c26e4 commit f31397c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

.changeset/puny-bikes-bow.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"agents": patch
3+
---
4+
5+
fix: dequeue items in DB after each task is complete
6+
7+
Prevents a single failure from causing all items in the queue from being retried (including previously processed items that were successful).

packages/agents/src/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,6 @@ export class Agent<Env, State = unknown> extends Server<Env> {
927927
}
928928
this._flushingQueue = true;
929929
while (true) {
930-
const executed: string[] = [];
931930
const result = this.sql<QueueItem<string>>`
932931
SELECT * FROM cf_agents_queues
933932
ORDER BY created_at ASC
@@ -959,13 +958,10 @@ export class Agent<Env, State = unknown> extends Server<Env> {
959958
queueItem: QueueItem<string>
960959
) => Promise<void>
961960
).bind(this)(JSON.parse(row.payload as string), row);
962-
executed.push(row.id);
961+
await this.dequeue(row.id);
963962
}
964963
);
965964
}
966-
for (const id of executed) {
967-
await this.dequeue(id);
968-
}
969965
}
970966
this._flushingQueue = false;
971967
}

0 commit comments

Comments
 (0)