diff --git a/package.json b/package.json index 4a7238d5c..ac148caff 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "@skyra/jaro-winkler": "^1.1.1", "adm-zip": "~0.5.15", "ajv": "~8.17.1", - "apify-client": "~2.22.0", + "apify-client": "^2.22.0", "archiver": "~7.0.1", "axios": "^1.11.0", "chalk": "~5.6.0", diff --git a/src/commands/actors/push.ts b/src/commands/actors/push.ts index 953f7da6b..5b6683714 100644 --- a/src/commands/actors/push.ts +++ b/src/commands/actors/push.ts @@ -198,6 +198,12 @@ export class ActorsPushCommand extends ApifyCommand { }, ], }; + + // Enable standby mode if configured in actor.json + if (actorConfig!.usesStandbyMode) { + newActor.actorStandby = { isEnabled: true }; + } + actor = await apifyClient.actors().create(newActor); actorId = actor.id; isActorCreatedNow = true; diff --git a/test/api/commands/push.test.ts b/test/api/commands/push.test.ts index 7ea725077..1fca6f3ad 100644 --- a/test/api/commands/push.test.ts +++ b/test/api/commands/push.test.ts @@ -362,7 +362,6 @@ describe('[api] apify push', () => { await testRunCommand(ActorsPushCommand, { args_actorId: testActor.id, flags_noPrompt: true }); testActor = (await testActorClient.get())!; - if (testActor) await testActorClient.delete(); // Title and description should be preserved from the original actor @@ -372,6 +371,78 @@ describe('[api] apify push', () => { TEST_TIMEOUT, ); + it( + 'should enable standby mode when usesStandbyMode is true in actor.json', + async () => { + const actorJson = JSON.parse(readFileSync(joinPath(LOCAL_CONFIG_PATH), 'utf8')); + + actorJson.name = `${actorJson.name}-standBy-test`; + actorJson.usesStandbyMode = true; + + writeFileSync(joinPath(LOCAL_CONFIG_PATH), JSON.stringify(actorJson, null, '\t'), { flag: 'w' }); + + await testRunCommand(ActorsPushCommand, { flags_noPrompt: true, flags_force: true }); + + const userInfo = await getLocalUserInfo(); + const actorId = `${userInfo.username}/${actorJson.name}`; + 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({ + 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 not enable standby mode on existing actor when usesStandbyMode is true in actor.json', + async () => { + // Create an actor without standby mode first + const testActorWithTitleDesc = { + ...TEST_ACTOR, + name: `${TEST_ACTOR.name}-standBy-rewrite-test`, + }; + const testActor = await testUserClient.actors().create(testActorWithTitleDesc); + 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); + + // Enable standby + const actorJson = JSON.parse(readFileSync(joinPath(LOCAL_CONFIG_PATH), 'utf8')); + actorJson.usesStandbyMode = true; + writeFileSync(joinPath(LOCAL_CONFIG_PATH), JSON.stringify(actorJson, null, '\t'), { flag: 'w' }); + + // 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 standby is not enabled after push + expect(updatedActor?.actorStandby?.isEnabled).to.not.be.eql(true); + if (updatedActor) await testActorClient.delete(); + }, + TEST_TIMEOUT, + ); + it( 'should not push Actor when there are no files to push', async () => { diff --git a/yarn.lock b/yarn.lock index 63bb8a91f..c418f4702 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2300,7 +2300,7 @@ __metadata: adm-zip: "npm:~0.5.15" ajv: "npm:~8.17.1" apify: "npm:^3.2.4" - apify-client: "npm:~2.22.0" + apify-client: "npm:^2.22.0" archiver: "npm:~7.0.1" axios: "npm:^1.11.0" chalk: "npm:~5.6.0" @@ -2368,7 +2368,7 @@ __metadata: languageName: node linkType: hard -"apify-client@npm:~2.22.0": +"apify-client@npm:^2.22.0": version: 2.22.0 resolution: "apify-client@npm:2.22.0" dependencies: