Skip to content
3 changes: 2 additions & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ DESCRIPTION
Customize with --memory and --timeout flags.

USAGE
$ apify task run <taskId> [-b <value>] [-m <value>]
$ apify task run <taskId> [-b <value>] [--json] [-m <value>]
[-t <value>]

ARGUMENTS
Expand All @@ -1574,6 +1574,7 @@ ARGUMENTS
FLAGS
-b, --build=<value> Tag or number of the build to run
(e.g. "latest" or "1.2.34").
--json Format the command output as JSON

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Needs a period at the end :D

@l2ysho l2ysho Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah this follows me everywhere :D It is fixed in #1168 so when we merge I will sync it here

-m, --memory=<value> Amount of memory allocated for the
Task run, in megabytes.
-t, --timeout=<value> Timeout for the Task run in seconds.
Expand Down
39 changes: 14 additions & 25 deletions src/commands/actors/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@ import {
} from 'apify-client';
import chalk from 'chalk';

import { ACTOR_JOB_STATUSES } from '@apify/consts';

import { ApifyCommand, StdinMode } from '../../lib/command-framework/apify-command.js';
import { Args } from '../../lib/command-framework/args.js';
import { Flags } from '../../lib/command-framework/flags.js';
import { getInputOverride } from '../../lib/commands/resolve-input.js';
import { runActorOrTaskOnCloud, SharedRunOnCloudFlags } from '../../lib/commands/run-on-cloud.js';
import { finalizeRun, runUrl } from '../../lib/commands/run-result.js';
import { CommandExitCodes, LOCAL_CONFIG_PATH } from '../../lib/consts.js';
import { error, simpleLog } from '../../lib/outputs.js';
import {
getLocalConfig,
getLocalUserInfo,
getLoggedClientOrThrow,
printJsonToStdout,
TimestampFormatter,
} from '../../lib/utils.js';
import { getLocalConfig, getLocalUserInfo, getLoggedClientOrThrow, TimestampFormatter } from '../../lib/utils.js';

export class ActorsCallCommand extends ApifyCommand<typeof ActorsCallCommand> {
static override name = 'call' as const;
Expand Down Expand Up @@ -146,9 +143,6 @@ export class ActorsCallCommand extends ApifyCommand<typeof ActorsCallCommand> {
let runStarted = false;
let run: ActorRun;

let url: string;
let datasetUrl: string;

const iterator = runActorOrTaskOnCloud(apifyClient, {
actorOrTaskData: {
id: actorId,
Expand All @@ -170,8 +164,7 @@ export class ActorsCallCommand extends ApifyCommand<typeof ActorsCallCommand> {

// A *lot* is copied from `runs info`
if (!this.flags.silent) {
url = `https://console.apify.com/actors/${actorId}/runs/${yieldedRun.id}`;
datasetUrl = `https://console.apify.com/storage/datasets/${yieldedRun.defaultDatasetId}`;
const url = runUrl(actorId, yieldedRun.id);

const message: string[] = [`${chalk.yellow('Started')}: ${TimestampFormatter.display(yieldedRun.startedAt)}`];

Expand Down Expand Up @@ -220,23 +213,19 @@ export class ActorsCallCommand extends ApifyCommand<typeof ActorsCallCommand> {
}
}

await finalizeRun({
apifyClient,
run: run!,
operation: 'call',
json: this.flags.json,
silent: this.flags.silent,
});

if (this.flags.json) {
printJsonToStdout(run!);
return;
}

if (!this.flags.silent) {
simpleLog({
message: [
'',
`${chalk.blue('Export results')}: ${datasetUrl!}`,
`${chalk.blue('View on Apify Console')}: ${url!}`,
].join('\n'),
stdout: true,
});
}

if (this.flags.outputDataset) {
if (this.flags.outputDataset && run!.status === ACTOR_JOB_STATUSES.SUCCEEDED) {
const datasetId = run!.defaultDatasetId;

let info: Dataset;
Expand Down
23 changes: 8 additions & 15 deletions src/commands/task/run.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { ApifyClient, TaskStartOptions } from 'apify-client';
import chalk from 'chalk';
import type { ActorRun, ApifyClient, TaskStartOptions } from 'apify-client';

import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
import { Args } from '../../lib/command-framework/args.js';
import { runActorOrTaskOnCloud, SharedRunOnCloudFlags } from '../../lib/commands/run-on-cloud.js';
import { simpleLog } from '../../lib/outputs.js';
import { finalizeRun } from '../../lib/commands/run-result.js';
import { getLocalUserInfo, getLoggedClientOrThrow } from '../../lib/utils.js';

export class TaskRunCommand extends ApifyCommand<typeof TaskRunCommand> {
Expand All @@ -29,6 +28,8 @@ export class TaskRunCommand extends ApifyCommand<typeof TaskRunCommand> {

static override flags = SharedRunOnCloudFlags('Task');

static override enableJsonFlag = true;

static override args = {
taskId: Args.string({
required: true,
Expand Down Expand Up @@ -59,8 +60,7 @@ export class TaskRunCommand extends ApifyCommand<typeof TaskRunCommand> {
runOpts.memory = this.flags.memory;
}

let url: string;
let datasetUrl: string;
let run!: ActorRun;

const iterator = runActorOrTaskOnCloud(apifyClient, {
actorOrTaskData: {
Expand All @@ -70,22 +70,15 @@ export class TaskRunCommand extends ApifyCommand<typeof TaskRunCommand> {
},
runOptions: runOpts,
type: 'Task',
waitForRunToFinish: true,
printRunLogs: true,
});

for await (const yieldedRun of iterator) {
url = `https://console.apify.com/actors/${yieldedRun.actId}/runs/${yieldedRun.id}`;
datasetUrl = `https://console.apify.com/storage/datasets/${yieldedRun.defaultDatasetId}`;
run = yieldedRun;
}

simpleLog({
message: [
'',
`${chalk.blue('Export results')}: ${datasetUrl!}`,
`${chalk.blue('View on Apify Console')}: ${url!}`,
].join('\n'),
stdout: true,
});
await finalizeRun({ apifyClient, run, operation: 'task-run', json: this.flags.json });
}

private async resolveTaskId(client: ApifyClient, usernameOrId: string) {
Expand Down
20 changes: 3 additions & 17 deletions src/lib/commands/run-on-cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import chalk from 'chalk';
import { ACTOR_JOB_STATUSES } from '@apify/consts';

import { Flags } from '../command-framework/flags.js';
import { CommandExitCodes } from '../consts.js';
import { useAbortJobOnSignal } from '../hooks/useAbortJobOnSignal.js';
import { error, run as runLog, success, warning } from '../outputs.js';
import { run as runLog, warning } from '../outputs.js';
import { outputJobLog } from '../utils.js';
import { resolveInput } from './resolve-input.js';

Expand Down Expand Up @@ -151,21 +150,8 @@ export async function* runActorOrTaskOnCloud(apifyClient: ApifyClient, options:
}
}

if (!silent) {
if (run.status === ACTOR_JOB_STATUSES.SUCCEEDED) {
success({ message: `${type} finished.` });
} else if (run.status === ACTOR_JOB_STATUSES.RUNNING) {
warning({ message: `${type} is still running!` });
} else if (run.status === ACTOR_JOB_STATUSES.ABORTED || run.status === ACTOR_JOB_STATUSES.ABORTING) {
warning({ message: `${type} was aborted!` });
process.exitCode = CommandExitCodes.RunAborted;
} else {
error({ message: `${type} failed!` });
process.exitCode = CommandExitCodes.RunFailed;
}
}

// Return the finished run
// Return the finished run. Presenting the final status and setting the exit code is the
// caller's responsibility.
yield run;
}

Expand Down
Loading
Loading