Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/commands/actors/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ const DEFAULT_ACTOR_VERSION_NUMBER = '0.0';
// that changes, we have to add it.
const DEFAULT_BUILD_TAG = 'latest';

// Default standby mode configuration when usesStandbyMode is enabled in actor.json
const DEFAULT_STANDBY_OPTIONS = {
isEnabled: true,
disableStandbyFieldsOverride: false,
maxRequestsPerActorRun: 4,
desiredRequestsPerActorRun: 3,
idleTimeoutSecs: 300,
build: 'latest',
memoryMbytes: 1024,
shouldPassActorInput: false,
};

Comment on lines +43 to +54
Copy link
Author

Choose a reason for hiding this comment

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

I stole this from console.apify.com, it is default preset send when user just enable standby mode. cc @vladfrangu

Copy link
Author

@l2ysho l2ysho Jan 13, 2026

Choose a reason for hiding this comment

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

my idea was result should be the same no matter if I use CLI or console UI

export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
static override name = 'push' as const;

Expand Down Expand Up @@ -196,17 +208,30 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
},
],
};

// Enable standby mode if configured in actor.json
if (actorConfig!.usesStandbyMode) {
newActor.actorStandby = DEFAULT_STANDBY_OPTIONS as ActorCollectionCreateOptions['actorStandby'];
Copy link
Author

Choose a reason for hiding this comment

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

ActorCollectionCreateOptions type look little bit out of date -> StandBy type missing disableStandbyFieldsOverride and shouldPassActorInput

}

actor = await apifyClient.actors().create(newActor);
actorId = actor.id;
isActorCreatedNow = true;
info({ message: `Created Actor with name ${actorConfig!.name} on Apify.` });
}
}

const actorClient = apifyClient.actor(actorId);

// Update standby mode on existing actor if configured in actor.json but not enabled on actor
if (!isActorCreatedNow && actorConfig!.usesStandbyMode && !actor.actorStandby?.isEnabled) {
await actorClient.update({ actorStandby: DEFAULT_STANDBY_OPTIONS });
info({ message: 'Enabled standby mode for Actor.' });
}

info({ message: `Deploying Actor '${actorConfig!.name}' to Apify.` });

const filesSize = await sumFilesSizeInBytes(filePathsToPush, cwd);
const actorClient = apifyClient.actor(actorId);

let sourceType;
let sourceFiles;
Expand Down
104 changes: 104 additions & 0 deletions test/api/commands/push.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,108 @@
},
TEST_TIMEOUT,
);

it(
'should enable standby mode when usesStandbyMode is true in actor.json',
async () => {
toggleCwdBetweenFullAndParentPath();

const standbyActorName = `${ACTOR_NAME}-standby`;

await mkdir(joinCwdPath(standbyActorName), { recursive: true });
forceNewCwd(standbyActorName);

// Create a minimal actor with usesStandbyMode enabled
const actorJson = {
actorSpecification: 1,
name: standbyActorName,
version: '0.0',
buildTag: 'latest',
usesStandbyMode: true,
};

await writeFile(joinPath(LOCAL_CONFIG_PATH), JSON.stringify(actorJson, null, '\t'));

await testRunCommand(ActorsPushCommand, { flags_noPrompt: true, flags_force: true });

const userInfo = await getLocalUserInfo();
const actorId = `${userInfo.username}/${standbyActorName}`;
actorsForCleanup.add(actorId);
const createdActorClient = testUserClient.actor(actorId);
const createdActor = await createdActorClient.get();

// Verify all standby options are set to default values
expect(createdActor?.actorStandby).to.be.eql({

Check failure on line 383 in test/api/commands/push.test.ts

View workflow job for this annotation

GitHub Actions / API Tests

test/api/commands/push.test.ts > [api] apify push > should enable standby mode when usesStandbyMode is true in actor.json

AssertionError: expected undefined to deeply equal { isEnabled: true, …(7) } - Expected: { "build": "latest", "desiredRequestsPerActorRun": 3, "disableStandbyFieldsOverride": false, "idleTimeoutSecs": 300, "isEnabled": true, "maxRequestsPerActorRun": 4, "memoryMbytes": 1024, "shouldPassActorInput": false, } + Received: undefined ❯ test/api/commands/push.test.ts:383:45

Check failure on line 383 in test/api/commands/push.test.ts

View workflow job for this annotation

GitHub Actions / API Tests

test/api/commands/push.test.ts > [api] apify push > should enable standby mode when usesStandbyMode is true in actor.json

AssertionError: expected undefined to deeply equal { isEnabled: true, …(7) } - Expected: { "build": "latest", "desiredRequestsPerActorRun": 3, "disableStandbyFieldsOverride": false, "idleTimeoutSecs": 300, "isEnabled": true, "maxRequestsPerActorRun": 4, "memoryMbytes": 1024, "shouldPassActorInput": false, } + Received: undefined ❯ test/api/commands/push.test.ts:383:45

Check failure on line 383 in test/api/commands/push.test.ts

View workflow job for this annotation

GitHub Actions / API Tests

test/api/commands/push.test.ts > [api] apify push > should enable standby mode when usesStandbyMode is true in actor.json

AssertionError: expected undefined to deeply equal { isEnabled: true, …(7) } - Expected: { "build": "latest", "desiredRequestsPerActorRun": 3, "disableStandbyFieldsOverride": false, "idleTimeoutSecs": 300, "isEnabled": true, "maxRequestsPerActorRun": 4, "memoryMbytes": 1024, "shouldPassActorInput": false, } + Received: undefined ❯ test/api/commands/push.test.ts:383:45

Check failure on line 383 in test/api/commands/push.test.ts

View workflow job for this annotation

GitHub Actions / API Tests

test/api/commands/push.test.ts > [api] apify push > should enable standby mode when usesStandbyMode is true in actor.json

AssertionError: expected undefined to deeply equal { isEnabled: true, …(7) } - Expected: { "build": "latest", "desiredRequestsPerActorRun": 3, "disableStandbyFieldsOverride": false, "idleTimeoutSecs": 300, "isEnabled": true, "maxRequestsPerActorRun": 4, "memoryMbytes": 1024, "shouldPassActorInput": false, } + Received: undefined ❯ test/api/commands/push.test.ts:383:45
isEnabled: true,
disableStandbyFieldsOverride: false,
maxRequestsPerActorRun: 4,
desiredRequestsPerActorRun: 3,
idleTimeoutSecs: 300,
build: 'latest',
memoryMbytes: 1024,
shouldPassActorInput: false,
});

if (createdActor) await createdActorClient.delete();
},
TEST_TIMEOUT,
);

it(
'should enable standby mode on existing actor when usesStandbyMode is true in actor.json',
async () => {
toggleCwdBetweenFullAndParentPath();

// Create an actor without standby mode first
const testActorWithoutStandby = {
...TEST_ACTOR,
name: `${ACTOR_NAME}-standby-update`,
};
const testActor = await testUserClient.actors().create(testActorWithoutStandby);

Check failure on line 409 in test/api/commands/push.test.ts

View workflow job for this annotation

GitHub Actions / API Tests

test/api/commands/push.test.ts > [api] apify push > should enable standby mode on existing actor when usesStandbyMode is true in actor.json

ApifyApiError: Some other Actor already has this name ("cli-push-ejmxdgun23-linux-standby-update"). ❯ makeRequest node_modules/apify-client/dist/http_client.js:216:30 ❯ ActorCollectionClient._create node_modules/apify-client/dist/base/resource_collection_client.js:29:26 ❯ test/api/commands/push.test.ts:409:22 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { clientMethod: 'ActorCollectionClient.create', statusCode: 409, attempt: 1, httpMethod: 'post', path: '/v2/acts', originalStack: '\n at makeRequest (/home/runner/work/apify-cli/apify-cli/node_modules/apify-client/dist/http_client.js:216:30)\n at processTicksAndRejections (node:internal/process/task_queues:103:5)\n at ActorCollectionClient._create (/home/runner/work/apify-cli/apify-cli/node_modules/apify-client/dist/base/resource_collection_client.js:29:26)\n at /home/runner/work/apify-cli/apify-cli/test/api/commands/push.test.ts:409:22\n at file:///home/runner/work/apify-cli/apify-cli/node_modules/@vitest/runner/dist/index.js:915:20', data: undefined, _safelyParsePathFromResponse: 'Function<_safelyParsePathFromResponse>', _extractClientAndMethodFromStack: 'Function<_extractClientAndMethodFromStack>', _createApiStack: 'Function<_createApiStack>' }

Check failure on line 409 in test/api/commands/push.test.ts

View workflow job for this annotation

GitHub Actions / API Tests

test/api/commands/push.test.ts > [api] apify push > should enable standby mode on existing actor when usesStandbyMode is true in actor.json

ApifyApiError: Some other Actor already has this name ("cli-push-ejmxdgun23-linux-standby-update"). ❯ makeRequest node_modules/apify-client/dist/http_client.js:216:30 ❯ ActorCollectionClient._create node_modules/apify-client/dist/base/resource_collection_client.js:29:26 ❯ test/api/commands/push.test.ts:409:22 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { clientMethod: 'ActorCollectionClient.create', statusCode: 409, attempt: 1, httpMethod: 'post', path: '/v2/acts', originalStack: '\n at makeRequest (/home/runner/work/apify-cli/apify-cli/node_modules/apify-client/dist/http_client.js:216:30)\n at processTicksAndRejections (node:internal/process/task_queues:103:5)\n at ActorCollectionClient._create (/home/runner/work/apify-cli/apify-cli/node_modules/apify-client/dist/base/resource_collection_client.js:29:26)\n at /home/runner/work/apify-cli/apify-cli/test/api/commands/push.test.ts:409:22\n at file:///home/runner/work/apify-cli/apify-cli/node_modules/@vitest/runner/dist/index.js:915:20', data: undefined, _safelyParsePathFromResponse: 'Function<_safelyParsePathFromResponse>', _extractClientAndMethodFromStack: 'Function<_extractClientAndMethodFromStack>', _createApiStack: 'Function<_createApiStack>' }

Check failure on line 409 in test/api/commands/push.test.ts

View workflow job for this annotation

GitHub Actions / API Tests

test/api/commands/push.test.ts > [api] apify push > should enable standby mode on existing actor when usesStandbyMode is true in actor.json

ApifyApiError: Some other Actor already has this name ("cli-push-ejmxdgun23-linux-standby-update"). ❯ makeRequest node_modules/apify-client/dist/http_client.js:216:30 ❯ ActorCollectionClient._create node_modules/apify-client/dist/base/resource_collection_client.js:29:26 ❯ test/api/commands/push.test.ts:409:22 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { clientMethod: 'ActorCollectionClient.create', statusCode: 409, attempt: 1, httpMethod: 'post', path: '/v2/acts', originalStack: '\n at makeRequest (/home/runner/work/apify-cli/apify-cli/node_modules/apify-client/dist/http_client.js:216:30)\n at processTicksAndRejections (node:internal/process/task_queues:103:5)\n at ActorCollectionClient._create (/home/runner/work/apify-cli/apify-cli/node_modules/apify-client/dist/base/resource_collection_client.js:29:26)\n at /home/runner/work/apify-cli/apify-cli/test/api/commands/push.test.ts:409:22\n at file:///home/runner/work/apify-cli/apify-cli/node_modules/@vitest/runner/dist/index.js:915:20', data: undefined, _safelyParsePathFromResponse: 'Function<_safelyParsePathFromResponse>', _extractClientAndMethodFromStack: 'Function<_extractClientAndMethodFromStack>', _createApiStack: 'Function<_createApiStack>' }
actorsForCleanup.add(testActor.id);
const testActorClient = testUserClient.actor(testActor.id);

// Verify standby is not enabled initially
const initialActor = await testActorClient.get();
expect(initialActor?.actorStandby?.isEnabled).to.not.be.eql(true);

await mkdir(joinCwdPath(testActorWithoutStandby.name), { recursive: true });
forceNewCwd(testActorWithoutStandby.name);

// Create actor.json with usesStandbyMode enabled
const actorJson = {
actorSpecification: 1,
name: testActorWithoutStandby.name,
version: '0.0',
buildTag: 'latest',
usesStandbyMode: true,
};

await writeFile(joinPath(LOCAL_CONFIG_PATH), JSON.stringify(actorJson, null, '\t'));

// Push to existing actor - this should update standby mode
await testRunCommand(ActorsPushCommand, {
args_actorId: testActor.id,
flags_noPrompt: true,
flags_force: true,
});

const updatedActor = await testActorClient.get();

// Verify all standby options are set to default values
expect(updatedActor?.actorStandby).to.be.eql({

Check failure on line 441 in test/api/commands/push.test.ts

View workflow job for this annotation

GitHub Actions / API Tests

test/api/commands/push.test.ts > [api] apify push > should enable standby mode on existing actor when usesStandbyMode is true in actor.json

AssertionError: expected undefined to deeply equal { isEnabled: true, …(7) } - Expected: { "build": "latest", "desiredRequestsPerActorRun": 3, "disableStandbyFieldsOverride": false, "idleTimeoutSecs": 300, "isEnabled": true, "maxRequestsPerActorRun": 4, "memoryMbytes": 1024, "shouldPassActorInput": false, } + Received: undefined ❯ test/api/commands/push.test.ts:441:45
isEnabled: true,
disableStandbyFieldsOverride: false,
maxRequestsPerActorRun: 4,
desiredRequestsPerActorRun: 3,
idleTimeoutSecs: 300,
build: 'latest',
memoryMbytes: 1024,
shouldPassActorInput: false,
});

if (updatedActor) await testActorClient.delete();
},
TEST_TIMEOUT,
);
});
Loading