Skip to content

Commit 519aa43

Browse files
authored
feat(actors): enables standby mode via actor.json (#991)
Fix `usesStandbyMode` not being applied when pushing Actor via CLI ### Problem When creating an Actor locally using `apify create my-actor -t ts-mcp-server` and then pushing it with `apify push`, the `usesStandbyMode: true` setting from `actor.json` was being ignored. The Actor would be created on the platform without standby mode enabled, even though the template explicitly sets this option. In contrast, cloning the same template directly from the Apify Console UI correctly enabled standby mode. ### Root Cause The `push` command was not reading the `usesStandbyMode` property from `actor.json` and was not passing it to the Apify API when creating or updating Actors. ### Changes - `src/commands/actors/push.ts`: Added standby mode support for both new and existing Actors - `test/api/commands/push.test.ts`: Added two API tests to verify standby mode is correctly enabled ### Testing ```bash apify create my-actor -t ts-mcp-server cd my-actor apify push ``` closes #913
1 parent ce26f60 commit 519aa43

4 files changed

Lines changed: 81 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"@skyra/jaro-winkler": "^1.1.1",
8181
"adm-zip": "~0.5.15",
8282
"ajv": "~8.17.1",
83-
"apify-client": "~2.22.0",
83+
"apify-client": "^2.22.0",
8484
"archiver": "~7.0.1",
8585
"axios": "^1.11.0",
8686
"chalk": "~5.6.0",

src/commands/actors/push.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
198198
},
199199
],
200200
};
201+
202+
// Enable standby mode if configured in actor.json
203+
if (actorConfig!.usesStandbyMode) {
204+
newActor.actorStandby = { isEnabled: true };
205+
}
206+
201207
actor = await apifyClient.actors().create(newActor);
202208
actorId = actor.id;
203209
isActorCreatedNow = true;

test/api/commands/push.test.ts

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@ describe('[api] apify push', () => {
362362
await testRunCommand(ActorsPushCommand, { args_actorId: testActor.id, flags_noPrompt: true });
363363

364364
testActor = (await testActorClient.get())!;
365-
366365
if (testActor) await testActorClient.delete();
367366

368367
// Title and description should be preserved from the original actor
@@ -372,6 +371,78 @@ describe('[api] apify push', () => {
372371
TEST_TIMEOUT,
373372
);
374373

374+
it(
375+
'should enable standby mode when usesStandbyMode is true in actor.json',
376+
async () => {
377+
const actorJson = JSON.parse(readFileSync(joinPath(LOCAL_CONFIG_PATH), 'utf8'));
378+
379+
actorJson.name = `${actorJson.name}-standBy-test`;
380+
actorJson.usesStandbyMode = true;
381+
382+
writeFileSync(joinPath(LOCAL_CONFIG_PATH), JSON.stringify(actorJson, null, '\t'), { flag: 'w' });
383+
384+
await testRunCommand(ActorsPushCommand, { flags_noPrompt: true, flags_force: true });
385+
386+
const userInfo = await getLocalUserInfo();
387+
const actorId = `${userInfo.username}/${actorJson.name}`;
388+
actorsForCleanup.add(actorId);
389+
const createdActorClient = testUserClient.actor(actorId);
390+
const createdActor = await createdActorClient.get();
391+
392+
// Verify all standby options are set to default values
393+
expect(createdActor?.actorStandby).to.be.eql({
394+
isEnabled: true,
395+
disableStandbyFieldsOverride: false,
396+
maxRequestsPerActorRun: 4,
397+
desiredRequestsPerActorRun: 3,
398+
idleTimeoutSecs: 300,
399+
build: 'latest',
400+
memoryMbytes: 1024,
401+
shouldPassActorInput: false,
402+
});
403+
404+
if (createdActor) await createdActorClient.delete();
405+
},
406+
TEST_TIMEOUT,
407+
);
408+
409+
it(
410+
'should not enable standby mode on existing actor when usesStandbyMode is true in actor.json',
411+
async () => {
412+
// Create an actor without standby mode first
413+
const testActorWithTitleDesc = {
414+
...TEST_ACTOR,
415+
name: `${TEST_ACTOR.name}-standBy-rewrite-test`,
416+
};
417+
const testActor = await testUserClient.actors().create(testActorWithTitleDesc);
418+
actorsForCleanup.add(testActor.id);
419+
const testActorClient = testUserClient.actor(testActor.id);
420+
421+
// Verify standby is not enabled initially
422+
const initialActor = await testActorClient.get();
423+
expect(initialActor?.actorStandby?.isEnabled).to.not.be.eql(true);
424+
425+
// Enable standby
426+
const actorJson = JSON.parse(readFileSync(joinPath(LOCAL_CONFIG_PATH), 'utf8'));
427+
actorJson.usesStandbyMode = true;
428+
writeFileSync(joinPath(LOCAL_CONFIG_PATH), JSON.stringify(actorJson, null, '\t'), { flag: 'w' });
429+
430+
// Push to existing actor - this should update standby mode
431+
await testRunCommand(ActorsPushCommand, {
432+
args_actorId: testActor.id,
433+
flags_noPrompt: true,
434+
flags_force: true,
435+
});
436+
437+
const updatedActor = await testActorClient.get();
438+
439+
// Verify standby is not enabled after push
440+
expect(updatedActor?.actorStandby?.isEnabled).to.not.be.eql(true);
441+
if (updatedActor) await testActorClient.delete();
442+
},
443+
TEST_TIMEOUT,
444+
);
445+
375446
it(
376447
'should not push Actor when there are no files to push',
377448
async () => {

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,7 +2300,7 @@ __metadata:
23002300
adm-zip: "npm:~0.5.15"
23012301
ajv: "npm:~8.17.1"
23022302
apify: "npm:^3.2.4"
2303-
apify-client: "npm:~2.22.0"
2303+
apify-client: "npm:^2.22.0"
23042304
archiver: "npm:~7.0.1"
23052305
axios: "npm:^1.11.0"
23062306
chalk: "npm:~5.6.0"
@@ -2368,7 +2368,7 @@ __metadata:
23682368
languageName: node
23692369
linkType: hard
23702370

2371-
"apify-client@npm:~2.22.0":
2371+
"apify-client@npm:^2.22.0":
23722372
version: 2.22.0
23732373
resolution: "apify-client@npm:2.22.0"
23742374
dependencies:

0 commit comments

Comments
 (0)