Skip to content

Commit

Permalink
Workflows commands (#7015)
Browse files Browse the repository at this point in the history
* add commands

* add command description

* change private beta message to open beta

* refactor to use defineCommand util

* add changeset

* update snapshots

* remove extraneous periods

* remove redundant file

Co-authored-by: Luís Duarte <lduarte@cloudflare.com>
  • Loading branch information
RamIdeas and LuisDuarte1 authored Oct 18, 2024
1 parent 244aa57 commit 48152d6
Show file tree
Hide file tree
Showing 17 changed files with 776 additions and 0 deletions.
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",
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",
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

0 comments on commit 48152d6

Please sign in to comment.