-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DeliveryDelay and RetryDelay to create Queue and Add Worker Consu…
…mer commands. (#5102) * Added builders for consumer and queue POST bodies * Unit tests for queues create with delivery delay * Added error handling for invalid queue settings * Helper Text * Unit tests for consumer add with retry settings * Updated tests check for no-parameter and parameter * PR suggestions * Changed yargs.fail error handling * Removed delivery delay from create consumer and queue * Prettier run * Removed stale comment * Update packages/wrangler/src/queues/cli/commands/create.ts Co-authored-by: MrBBot <me@mrbbot.dev> * Update packages/wrangler/src/queues/cli/commands/consumer/add.ts Co-authored-by: MrBBot <me@mrbbot.dev> * Update packages/wrangler/src/__tests__/queues.test.ts Co-authored-by: MrBBot <me@mrbbot.dev> * Update .changeset/warm-seahorses-trade.md Co-authored-by: MrBBot <me@mrbbot.dev> * Tests passing * Updated commands to support HTTP Pull consumers --------- Co-authored-by: MrBBot <me@mrbbot.dev>
- Loading branch information
Showing
9 changed files
with
176 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler": minor | ||
--- | ||
|
||
feature: add support for queue delivery controls on `wrangler queues create` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,62 @@ | ||
import { readConfig } from "../../../config"; | ||
import { CommandLineArgsError } from "../../../index"; | ||
import { logger } from "../../../logger"; | ||
import { createQueue } from "../../client"; | ||
import { handleFetchError } from "../../utils"; | ||
import type { | ||
CommonYargsArgv, | ||
StrictYargsOptionsToInterface, | ||
} from "../../../yargs-types"; | ||
import type { CreateQueueBody } from "../../client"; | ||
|
||
export function options(yargs: CommonYargsArgv) { | ||
return yargs.positional("name", { | ||
type: "string", | ||
demandOption: true, | ||
description: "The name of the queue", | ||
}); | ||
return yargs | ||
.positional("name", { | ||
type: "string", | ||
demandOption: true, | ||
description: "The name of the queue", | ||
}) | ||
.options({ | ||
"delivery-delay-secs": { | ||
type: "number", | ||
describe: | ||
"How long a published message should be delayed for, in seconds. Must be a positive integer", | ||
}, | ||
}); | ||
} | ||
|
||
function createBody( | ||
args: StrictYargsOptionsToInterface<typeof options> | ||
): CreateQueueBody { | ||
const body: CreateQueueBody = { | ||
queue_name: args.name, | ||
}; | ||
|
||
if (Array.isArray(args.deliveryDelaySecs)) { | ||
throw new CommandLineArgsError( | ||
"Cannot specify --delivery-delay-secs multiple times" | ||
); | ||
} | ||
|
||
if (args.deliveryDelaySecs != undefined) { | ||
body.settings = { | ||
delivery_delay: args.deliveryDelaySecs, | ||
}; | ||
} | ||
|
||
return body; | ||
} | ||
|
||
export async function handler( | ||
args: StrictYargsOptionsToInterface<typeof options> | ||
) { | ||
const config = readConfig(args.config, args); | ||
|
||
logger.log(`Creating queue ${args.name}.`); | ||
await createQueue(config, { queue_name: args.name }); | ||
logger.log(`Created queue ${args.name}.`); | ||
const body = createBody(args); | ||
try { | ||
logger.log(`Creating queue ${args.name}.`); | ||
await createQueue(config, body); | ||
logger.log(`Created queue ${args.name}.`); | ||
} catch (e) { | ||
handleFetchError(e as { code?: number }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const INVALID_CONSUMER_SETTINGS_ERROR = 100127; | ||
export const INVALID_QUEUE_SETTINGS_ERROR = 100128; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.