-
Notifications
You must be signed in to change notification settings - Fork 56
fix: builds abort, runs --status filter, and dataset command correctness #1316
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
Open
Ayush7614
wants to merge
5
commits into
apify:master
Choose a base branch
from
Ayush7614:feat/builds-abort-and-storage-fixes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+342
−68
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b8399a8
fix: add builds abort, runs status filter, and dataset command bugs
Ayush7614 1a50510
test: fix storage-size unit test import path
Ayush7614 c84554c
fix(builds): set non-zero exit code on log failures
Ayush7614 9833098
Merge branch 'master' into feat/builds-abort-and-storage-fixes
Ayush7614 7b49410
Merge branch 'master' into feat/builds-abort-and-storage-fixes
Ayush7614 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
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
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
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,85 @@ | ||
| import type { ApifyApiError } from 'apify-client'; | ||
|
|
||
| import { ACTOR_JOB_STATUSES } from '@apify/consts'; | ||
|
|
||
| import { ApifyCommand } from '../../lib/command-framework/apify-command.js'; | ||
| import { Args } from '../../lib/command-framework/args.js'; | ||
| import { error, success } from '../../lib/outputs.js'; | ||
| import { getLoggedClientOrThrow, printJsonToStdout } from '../../lib/utils.js'; | ||
|
|
||
| const runningStatuses = [ACTOR_JOB_STATUSES.READY, ACTOR_JOB_STATUSES.RUNNING]; | ||
|
|
||
| const abortingStatuses = [ACTOR_JOB_STATUSES.ABORTING, ACTOR_JOB_STATUSES.TIMING_OUT]; | ||
|
|
||
| export class BuildsAbortCommand extends ApifyCommand<typeof BuildsAbortCommand> { | ||
| static override name = 'abort' as const; | ||
|
|
||
| static override description = 'Aborts an Actor build that is currently in progress.'; | ||
|
|
||
| static override examples = [ | ||
| { | ||
| description: 'Abort a running Actor build.', | ||
| command: 'apify builds abort <buildId>', | ||
| }, | ||
| ]; | ||
|
|
||
| static override docsUrl = 'https://docs.apify.com/cli/docs/reference#apify-builds-abort'; | ||
|
|
||
| static override args = { | ||
| buildId: Args.string({ | ||
| required: true, | ||
| description: 'The build ID to abort.', | ||
| }), | ||
| }; | ||
|
|
||
| static override enableJsonFlag = true; | ||
|
|
||
| async run() { | ||
| const { buildId } = this.args; | ||
|
|
||
| const apifyClient = await getLoggedClientOrThrow(); | ||
|
|
||
| const build = await apifyClient.build(buildId).get(); | ||
|
|
||
| if (!build) { | ||
| error({ message: `Build with ID "${buildId}" was not found on your account.`, stdout: true }); | ||
| return; | ||
| } | ||
|
|
||
| if (!runningStatuses.includes(build.status as never)) { | ||
| if (abortingStatuses.includes(build.status as never)) { | ||
| error({ message: `Build with ID "${buildId}" is already aborting.`, stdout: true }); | ||
| } else if (build.status === ACTOR_JOB_STATUSES.ABORTED || build.status === ACTOR_JOB_STATUSES.TIMED_OUT) { | ||
| error({ message: `Build with ID "${buildId}" is already aborted.`, stdout: true }); | ||
| } else { | ||
| error({ | ||
| message: `Build with ID "${buildId}" cannot be aborted (status: ${build.status}).`, | ||
| stdout: true, | ||
| }); | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| try { | ||
| const result = await apifyClient.build(buildId).abort(); | ||
|
|
||
| if (this.flags.json) { | ||
| printJsonToStdout(result); | ||
| return; | ||
| } | ||
|
|
||
| success({ | ||
| message: `Triggered the abort of build "${buildId}".`, | ||
| stdout: true, | ||
| }); | ||
| } catch (err) { | ||
| const casted = err as ApifyApiError; | ||
|
|
||
| error({ | ||
| message: `Failed to abort build "${buildId}".\n ${casted.message || casted}`, | ||
| stdout: true, | ||
| }); | ||
| } | ||
| } | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This swallows log-fetch failures and reports success. Before, an exception from
outputJobLogpropagated and the command exited 1. Now, if the build exists butclient.log(id).get()5xx's or the log is gone, the user getsInfo: Log for build with ID "x":on stdout,Error: Failed to get log…on stderr, and$? == 0.Concretely:
apify builds log $ID > build.log && next-stepproceeds with an empty file.I see this was copied from
src/commands/runs/log.ts— but there the swallow is annotated (// This should never happen..., dropped in the copy), and regardless it's a new regression forbuilds log. Either rethrow, orprocess.exitCode = 1in the catch.Minor inconsistency while you're here: line 35 sends its error to stdout (
stdout: true) and line 44 to stderr, in the same command.