Skip to content

Commit 48548cd

Browse files
authored
fix: load initialCount in openRequestQueue() (#339)
1 parent 6433d9e commit 48548cd

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/apify/src/actor.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
818818

819819
this._ensureActorInit('openRequestQueue');
820820

821-
return this._openStorage(RequestQueue, queueIdOrName, options);
821+
const queue = await this._openStorage(RequestQueue, queueIdOrName, options);
822+
823+
// eslint-disable-next-line dot-notation
824+
queue['initialCount'] = (await queue.client.get())?.totalRequestCount ?? 0;
825+
826+
return queue;
822827
}
823828

824829
/**

test/apify/actor.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,15 @@ describe('Actor', () => {
604604
const queueId = 'abc';
605605
const options = { forceCloud: true };
606606
const openStorageSpy = vitest.spyOn(StorageManager.prototype, 'openStorage');
607-
openStorageSpy.mockImplementationOnce(async (i) => i);
608-
await sdk.openRequestQueue(queueId, options);
607+
608+
const mockRQ = { client: { get: () => ({ totalRequestCount: 10 }) } };
609+
610+
openStorageSpy.mockImplementationOnce(async () => mockRQ);
611+
const queue = await sdk.openRequestQueue(queueId, options);
609612
expect(openStorageSpy).toBeCalledWith(queueId, sdk.apifyClient);
610613
expect(openStorageSpy).toBeCalledTimes(1);
614+
615+
expect(queue.initialCount).toBe(10);
611616
});
612617

613618
test('openDataset should open storage', async () => {

0 commit comments

Comments
 (0)