Skip to content

fix: Use same client_key for Actor created request_queue and improve its metadata estimation #552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

Pijukatel
Copy link
Contributor

@Pijukatel Pijukatel commented Aug 19, 2025

Description

  • When creating RequestQueue from Actor on the platform or with force_cloud=True the client_key should be set to run_id. This ensures:
    • Each API call of the same RequestQueue instance that is using ApifyRequestQueueClient will be done with the same client_key and thus in metadata had_multiple_clients=False
    • Multiple instances of RequestQueue created by Actor.open_request_queue() on the platform share the same client_key and thus in metadata had_multiple_clients=False
    • On the platform, since the client_key is set to run_id, it remains the same for resurrected or migrated run, and thus in metadata had_multiple_clients=False
  • Improved reliability of had_multiple_clients allows better estimation of RequestQueue metadata.
    • When had_multiple_clients=False, it is possible to trust local estimation of the metadata.
    • When had_multiple_clients=True, local estimation is no longer valid, but still can, in some cases, improve estimation by being ahead of the delayed API update of the metadata. Therefore API-based metadata are fused with local metadata estimation to produce as good estimation as we can.
  • ApifyRequestQueueClient init changed to properly initialize from full metadata - to enable more reliable metadata after migration/resurrection or when using existing RequestQueue
  • During _list_head, if there is a call to API, use the available had_multiple_clients to update local estimation of this value. This is a cheap way of knowing if there is another client or not without the need to make a new API call. _list_head is called frequently enough to make the local estimation of had_multiple_clients decently good.

Issues

Testing

  • New tests added

@github-actions github-actions bot added this to the 121st sprint - Tooling team milestone Aug 19, 2025
@github-actions github-actions bot added t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics. labels Aug 19, 2025
@Pijukatel
Copy link
Contributor Author

Pijukatel commented Aug 19, 2025

As of now, the test_request_queue_not_had_multiple_clients_platform_resurrection will fail due to an already acknowledged bug on the platform, but that should be fixed in the near future.

In develop branch: https://github.com/apify/apify-worker/pull/1470

@Pijukatel Pijukatel requested review from vdusek and janbuchar August 19, 2025 11:50
@Pijukatel Pijukatel requested a review from vdusek August 22, 2025 08:11
@Pijukatel
Copy link
Contributor Author

The necessary fix on the platform was merged to master, and it is working now.

@Pijukatel Pijukatel marked this pull request as ready for review August 22, 2025 08:12
Copy link
Contributor

@vdusek vdusek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, let's see how it behaves...

I'm just not sure about the feat: 🙂, maybe rather a fix?

@Pijukatel Pijukatel changed the title feat: Use same client_key for Actor created request_queue and improve its metadata estimation fix: Use same client_key for Actor created request_queue and improve its metadata estimation Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Actor should use same client_key for all ApifyRequestQueue client calls
2 participants