-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Added pause and resume commands to manage Workflows #7121
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
Merged
edmundhung
merged 14 commits into
cloudflare:main
from
bruxodasilva:dferreira/workflows-add-pause-resume-cmds
Nov 4, 2024
Merged
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fc544bc
Added pause and resume commands to manage Workflows
bruxodasilva 722cf14
prettify check
bruxodasilva 4549584
Update packages/wrangler/src/workflows/commands/instances/pause.ts
bruxodasilva 0ccbb0c
Update packages/wrangler/src/workflows/commands/instances/resume.ts
bruxodasilva 56601ef
add happy path test for `pause`
emily-shen cd6a34d
added workflows cmds tests and fix delete not being implemented
bruxodasilva 45851c6
try to fix timezones
bruxodasilva c60723f
hidded workflows delete command from help as it is not yet implemented
bruxodasilva 6bc790c
Update packages/wrangler/src/__tests__/workflows.test.ts
bruxodasilva 656802d
Update packages/wrangler/src/__tests__/workflows.test.ts
bruxodasilva a0cad9b
fixed should get the list of instances given a name test
bruxodasilva a8641a3
better changeset
bruxodasilva c6c88f9
added mocked instance id when a workflow is triggered
bruxodasilva 3c777c4
prettify cleanup
bruxodasilva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 | ||
| --- | ||
|
|
||
| Added pause and resume commands to manage Workflows | ||
This file contains hidden or 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
68 changes: 68 additions & 0 deletions
68
packages/wrangler/src/workflows/commands/instances/pause.ts
This file contains hidden or 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,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", | ||
bruxodasilva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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
68
packages/wrangler/src/workflows/commands/instances/resume.ts
This file contains hidden or 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,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", | ||
bruxodasilva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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` | ||
| ); | ||
| }, | ||
| }); | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.