Skip to content

Commit b41cdd9

Browse files
committed
Use strings for outcome instead of numeric constants
Ref: cloudflare/workerd#961
1 parent 9aad545 commit b41cdd9

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

packages/miniflare/src/plugins/queues/gateway.ts

+13-14
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,17 @@ const DEFAULT_BATCH_TIMEOUT = 1; // second
1414
const DEFAULT_RETRIES = 2;
1515

1616
// https://github.com/cloudflare/workerd/blob/01b87642f4eac932aa9074d7e5eec4fd3c90968a/src/workerd/io/outcome.capnp
17-
const Outcome = {
18-
UNKNOWN: 0,
19-
OK: 1,
20-
EXCEPTION: 2,
21-
EXCEEDED_CPU: 3,
22-
KILL_SWITCH: 4,
23-
DAEMON_DOWN: 5,
24-
SCRIPT_NOT_FOUND: 6,
25-
CANCELED: 7,
26-
EXCEEDED_MEMORY: 8,
27-
} as const;
28-
const OutcomeSchema = z.nativeEnum(Outcome);
17+
const OutcomeSchema = z.enum([
18+
"unknown",
19+
"ok",
20+
"exception",
21+
"exceededCpu",
22+
"killSwitch",
23+
"daemonDown",
24+
"scriptNotFound",
25+
"cancelled",
26+
"exceededMemory",
27+
]);
2928

3029
const QueueResponseSchema = z.object({
3130
outcome: OutcomeSchema,
@@ -37,7 +36,7 @@ const QueueResponseSchema = z.object({
3736
});
3837
type QueueResponse = z.infer<typeof QueueResponseSchema>;
3938
const exceptionQueueResponse: QueueResponse = {
40-
outcome: Outcome.EXCEPTION,
39+
outcome: "exception",
4140
retryAll: false,
4241
ackAll: false,
4342
explicitRetries: [],
@@ -153,7 +152,7 @@ export class QueuesGateway {
153152

154153
// Get messages to retry. If dispatching the batch failed for any reason,
155154
// retry all messages.
156-
const retryAll = response.retryAll || response.outcome !== Outcome.OK;
155+
const retryAll = response.retryAll || response.outcome !== "ok";
157156
const explicitRetries = new Set(response.explicitRetries);
158157

159158
let failedMessages = 0;

0 commit comments

Comments
 (0)