Skip to content
Open
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
18 changes: 18 additions & 0 deletions 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
export const DEFAULT_STANDBY_OPTIONS = {
isEnabled: true,
disableStandbyFieldsOverride: false,
maxRequestsPerActorRun: 4,
desiredRequestsPerActorRun: 3,
idleTimeoutSecs: 300,
build: 'latest',
memoryMbytes: 1024,
shouldPassActorInput: false,
};

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

Expand Down Expand Up @@ -198,6 +210,12 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
},
],
};

// Enable standby mode if configured in actor.json
if (actorConfig!.usesStandbyMode) {
newActor.actorStandby = DEFAULT_STANDBY_OPTIONS;
}

actor = await apifyClient.actors().create(newActor);
actorId = actor.id;
isActorCreatedNow = true;
Expand Down
73 changes: 72 additions & 1 deletion test/api/commands/push.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 () => {
Expand Down