Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/violet-zoos-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

Added pause and resume commands to manage Workflows
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ defineCommand({
command: "wrangler workflows instances list",

metadata: {
description: "Instance related commands (list, describe, terminate...)",
description:
"Instance related commands (list, describe, terminate, pause, resume)",
owner: "Product: Workflows",
status: "open-beta",
},
Expand Down
68 changes: 68 additions & 0 deletions packages/wrangler/src/workflows/commands/instances/pause.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { fetchResult } from "../../../cfetch";
import { defineCommand } from "../../../core";
import { logger } from "../../../logger";
import { requireAuth } from "../../../user";
import type { Instance } from "../../types";

defineCommand({
command: "wrangler workflows instances pause",

metadata: {
description: "Pause a workflow instance",
owner: "Product: Workflows",
status: "open-beta",
},

positionalArgs: ["name", "id"],
args: {
name: {
describe: "Name of the workflow",
type: "string",
demandOption: true,
},
id: {
describe:
"ID of the instance - instead of an UUID you can type 'latest' to get the latest instance and describe it",
type: "string",
demandOption: true,
},
},

async handler(args, { config }) {
const accountId = await requireAuth(config);

let id = args.id;

if (id == "latest") {
const instances = (
await fetchResult<Instance[]>(
`/accounts/${accountId}/workflows/${args.name}/instances`
)
).sort((a, b) => b.created_on.localeCompare(a.created_on));

if (instances.length == 0) {
logger.error(
`There are no deployed instances in workflow "${args.name}"`
);
return;
}

id = instances[0].id;
}

await fetchResult(
`/accounts/${accountId}/workflows/${args.name}/instances/${id}/status`,
{
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ status: "pause" }),
}
);

logger.info(
`⏸️ The instance "${id}" from ${args.name} was paused successfully`
);
},
});
68 changes: 68 additions & 0 deletions packages/wrangler/src/workflows/commands/instances/resume.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { fetchResult } from "../../../cfetch";
import { defineCommand } from "../../../core";
import { logger } from "../../../logger";
import { requireAuth } from "../../../user";
import type { Instance } from "../../types";

defineCommand({
command: "wrangler workflows instances resume",

metadata: {
description: "Resume a workflow instance",
owner: "Product: Workflows",
status: "open-beta",
},

positionalArgs: ["name", "id"],
args: {
name: {
describe: "Name of the workflow",
type: "string",
demandOption: true,
},
id: {
describe:
"ID of the instance - instead of an UUID you can type 'latest' to get the latest instance and describe it",
type: "string",
demandOption: true,
},
},

async handler(args, { config }) {
const accountId = await requireAuth(config);

let id = args.id;

if (id == "latest") {
const instances = (
await fetchResult<Instance[]>(
`/accounts/${accountId}/workflows/${args.name}/instances`
)
).sort((a, b) => b.created_on.localeCompare(a.created_on));

if (instances.length == 0) {
logger.error(
`There are no deployed instances in workflow "${args.name}"`
);
return;
}

id = instances[0].id;
}

await fetchResult(
`/accounts/${accountId}/workflows/${args.name}/instances/${id}/status`,
{
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ status: "resume" }),
}
);

logger.info(
`🔄 The instance "${id}" from ${args.name} was resumed successfully`
);
},
});
2 changes: 2 additions & 0 deletions packages/wrangler/src/workflows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import "./commands/trigger";
import "./commands/instances/list";
import "./commands/instances/describe";
import "./commands/instances/terminate";
import "./commands/instances/pause";
import "./commands/instances/resume";

defineNamespace({
command: "wrangler workflows",
Expand Down
Loading