-
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
base: master
Are you sure you want to change the base?
Changes from all commits
b8399a8
1a50510
c84554c
9833098
7b49410
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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, | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| import process from 'node:process'; | ||
|
|
||
| import { ApifyCommand } from '../../lib/command-framework/apify-command.js'; | ||
| import { Args } from '../../lib/command-framework/args.js'; | ||
| import { info } from '../../lib/outputs.js'; | ||
| import { error, info } from '../../lib/outputs.js'; | ||
| import { getLoggedClientOrThrow, outputJobLog } from '../../lib/utils.js'; | ||
|
|
||
| export class BuildsLogCommand extends ApifyCommand<typeof BuildsLogCommand> { | ||
|
|
@@ -32,11 +34,21 @@ export class BuildsLogCommand extends ApifyCommand<typeof BuildsLogCommand> { | |
| const build = await apifyClient.build(buildId).get(); | ||
|
|
||
| if (!build) { | ||
| throw new Error(`Build with ID "${buildId}" was not found on your account.`); | ||
| error({ message: `Build with ID "${buildId}" was not found on your account.`, stdout: true }); | ||
| process.exitCode = 1; | ||
| return; | ||
| } | ||
|
|
||
| info({ message: `Log for build with ID "${buildId}":\n` }); | ||
| info({ message: `Log for build with ID "${buildId}":\n`, stdout: true }); | ||
|
|
||
| await outputJobLog({ job: build, apifyClient }); | ||
| try { | ||
| await outputJobLog({ job: build, apifyClient }); | ||
| } catch (err) { | ||
| error({ | ||
| message: `Failed to get log for build with ID "${buildId}": ${(err as Error).message}`, | ||
| stdout: true, | ||
| }); | ||
| process.exitCode = 1; | ||
| } | ||
|
Comment on lines
+44
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This swallows log-fetch failures and reports success. Before, an exception from Concretely: I see this was copied from Minor inconsistency while you're here: line 35 sends its error to stdout ( |
||
| } | ||
| } | ||
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.