Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflows commands #7015

Merged
merged 17 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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/moody-seals-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

add `wrangler workflows ...` commands
2 changes: 2 additions & 0 deletions packages/wrangler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
"blake3-wasm": "^2.1.5",
"chokidar": "^3.5.3",
"date-fns": "^4.1.0",
"esbuild": "0.17.19",
"itty-time": "^1.0.6",
"miniflare": "workspace:*",
"nanoid": "^3.3.3",
"path-to-regexp": "^6.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ describe("Command Registration", () => {
wrangler pubsub 📮 Manage Pub/Sub brokers [private beta]
wrangler dispatch-namespace 🏗️ Manage dispatch namespaces
wrangler ai 🤖 Manage AI models
wrangler workflows 🔁 Manage Workflows [open-beta]
wrangler login 🔓 Login to Cloudflare
wrangler logout 🚪 Logout from Cloudflare
wrangler whoami 🕵️ Retrieve your user information
Expand Down
2 changes: 2 additions & 0 deletions packages/wrangler/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe("wrangler", () => {
wrangler pubsub 📮 Manage Pub/Sub brokers [private beta]
wrangler dispatch-namespace 🏗️ Manage dispatch namespaces
wrangler ai 🤖 Manage AI models
wrangler workflows 🔁 Manage Workflows [open-beta]
wrangler login 🔓 Login to Cloudflare
wrangler logout 🚪 Logout from Cloudflare
wrangler whoami 🕵️ Retrieve your user information
Expand Down Expand Up @@ -117,6 +118,7 @@ describe("wrangler", () => {
wrangler pubsub 📮 Manage Pub/Sub brokers [private beta]
wrangler dispatch-namespace 🏗️ Manage dispatch namespaces
wrangler ai 🤖 Manage AI models
wrangler workflows 🔁 Manage Workflows [open-beta]
wrangler login 🔓 Login to Cloudflare
wrangler logout 🚪 Logout from Cloudflare
wrangler whoami 🕵️ Retrieve your user information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe("versions --help", () => {
wrangler pubsub 📮 Manage Pub/Sub brokers [private beta]
wrangler dispatch-namespace 🏗️ Manage dispatch namespaces
wrangler ai 🤖 Manage AI models
wrangler workflows 🔁 Manage Workflows [open-beta]
wrangler login 🔓 Login to Cloudflare
wrangler logout 🚪 Logout from Cloudflare
wrangler whoami 🕵️ Retrieve your user information
Expand Down
1 change: 1 addition & 0 deletions packages/wrangler/src/core/teams.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export type Teams =
| "Product: AI"
| "Product: Hyperdrive"
| "Product: Vectorize"
| "Product: Workflows"
| "Product: Cloudchamber";
4 changes: 4 additions & 0 deletions packages/wrangler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { generateHandler, generateOptions } from "./generate";
import { hyperdrive } from "./hyperdrive/index";
import { initHandler, initOptions } from "./init";
import "./kv";
import "./workflows";
import { logBuildFailure, logger, LOGGER_LEVELS } from "./logger";
import * as metrics from "./metrics";
import { mTlsCertificateCommands } from "./mtls-certificate/cli";
Expand Down Expand Up @@ -608,6 +609,9 @@ export function createCLIParser(argv: string[]) {
return ai(aiYargs.command(subHelp));
});

// workflows
register.registerNamespace("workflows");

// pipelines
wrangler.command("pipelines", false, (pipelinesYargs) => {
return pipelines(pipelinesYargs.command(subHelp));
Expand Down
33 changes: 33 additions & 0 deletions packages/wrangler/src/workflows/commands/delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { fetchResult } from "../../cfetch";
import { defineCommand } from "../../core";
import { logger } from "../../logger";
import { requireAuth } from "../../user";

defineCommand({
command: "wrangler workflows delete",
metadata: {
description:
"Delete workflow - when deleting a workflow, it will also delete it's own instances",
owner: "Product: Workflows",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might think about creating a separate owners config, which would help to keep this consistent over time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered this in the design but I think the granularity and colocation trump the duplication and especially since it will be infrequently changed

status: "open-beta",
},

args: {
name: {
describe: "Name of the workflow",
type: "string",
demandOption: true,
},
},
positionalArgs: ["name"],

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

await fetchResult(`/accounts/${accountId}/workflows/${args.name}`, {
method: "DELETE",
});

logger.info(`Workflow "${args.name}" was successfully removed`);
},
});
59 changes: 59 additions & 0 deletions packages/wrangler/src/workflows/commands/describe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { logRaw } from "@cloudflare/cli";
import { white } from "@cloudflare/cli/colors";
import { fetchResult } from "../../cfetch";
import { defineCommand } from "../../core";
import { requireAuth } from "../../user";
import formatLabelledValues from "../../utils/render-labelled-values";
import type { Version, Workflow } from "../types";

defineCommand({
command: "wrangler workflows describe",
metadata: {
description: "Describe Workflow resource",
owner: "Product: Workflows",
status: "open-beta",
},
args: {
name: {
describe: "Name of the workflow",
RamIdeas marked this conversation as resolved.
Show resolved Hide resolved
type: "string",
demandOption: true,
},
},
positionalArgs: ["name"],
async handler(args, { config }) {
const accountId = await requireAuth(config);

const workflow = await fetchResult<Workflow>(
`/accounts/${accountId}/workflows/${args.name}`
);

const versions = await fetchResult<Version[]>(
`/accounts/${accountId}/workflows/${args.name}/versions`
);

const latestVersion = versions[0];

logRaw(
formatLabelledValues({
Name: workflow.name,
Id: workflow.id,
"Script Name": workflow.script_name,
"Class Name": workflow.class_name,
"Created On": workflow.created_on,
"Modified On": workflow.modified_on,
})
);
logRaw(white("Latest Version:"));
logRaw(
formatLabelledValues(
{
Id: latestVersion.id,
"Created On": workflow.created_on,
"Modified On": workflow.modified_on,
},
{ indentationCount: 2 }
)
);
},
});
Loading
Loading