Skip to content

Commit

Permalink
fix: load initialCount in openRequestQueue() (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
barjin authored Nov 18, 2024
1 parent 6433d9e commit 48548cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/apify/src/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,12 @@ export class Actor<Data extends Dictionary = Dictionary> {

this._ensureActorInit('openRequestQueue');

return this._openStorage(RequestQueue, queueIdOrName, options);
const queue = await this._openStorage(RequestQueue, queueIdOrName, options);

// eslint-disable-next-line dot-notation
queue['initialCount'] = (await queue.client.get())?.totalRequestCount ?? 0;

return queue;
}

/**
Expand Down
9 changes: 7 additions & 2 deletions test/apify/actor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,15 @@ describe('Actor', () => {
const queueId = 'abc';
const options = { forceCloud: true };
const openStorageSpy = vitest.spyOn(StorageManager.prototype, 'openStorage');
openStorageSpy.mockImplementationOnce(async (i) => i);
await sdk.openRequestQueue(queueId, options);

const mockRQ = { client: { get: () => ({ totalRequestCount: 10 }) } };

openStorageSpy.mockImplementationOnce(async () => mockRQ);
const queue = await sdk.openRequestQueue(queueId, options);
expect(openStorageSpy).toBeCalledWith(queueId, sdk.apifyClient);
expect(openStorageSpy).toBeCalledTimes(1);

expect(queue.initialCount).toBe(10);
});

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

0 comments on commit 48548cd

Please sign in to comment.