Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: Implement RequestQueue class #25

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

Merged
merged 10 commits into from
Jan 24, 2023
Merged

Conversation

jirimoravcik
Copy link
Member

@jirimoravcik jirimoravcik commented Jan 18, 2023

Generic LRUCache implementing https://python.readthedocs.io/en/latest/library/collections.abc.html#collections.abc.MutableMapping

I want to add some validation to methods that have request as an argument. probably best way is to use Pydantic, we'll see...

I also added a Protocol for Storages that can be used instead of the ugly union. Protocol is basically implicit structural subtyping and seems to work ok https://peps.python.org/pep-0544/

@github-actions github-actions bot added this to the 55th sprint - Platform team milestone Jan 18, 2023
@github-actions github-actions bot added the t-core-services Issues with this label are in the ownership of the platform team. label Jan 18, 2023
@jirimoravcik jirimoravcik marked this pull request as ready for review January 20, 2023 21:44
Copy link
Member

@fnesveda fnesveda left a comment

Choose a reason for hiding this comment

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

Wow, looks pretty good! I had just a few small comments, but otherwise I think it's good to go.

It's crazy how much logic has to be there on top of our API, we should move this to the platform eventually.

from collections import OrderedDict
from datetime import datetime
from typing import Coroutine, Dict, Optional
from typing import OrderedDict as OrderedDictType
Copy link
Member

Choose a reason for hiding this comment

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

Can't wait until we can deprecate Python 3.8 🙂

_recently_handled: LRUCache[bool]
_assumed_total_count = 0
_assumed_handled_count = 0
_requests_cache: LRUCache[Dict]

def __init__(self, id: str, name: Optional[str], client: Union[ApifyClientAsync, MemoryStorage]) -> None:
"""TODO: docs (constructor should be "internal")."""
self._id = id
self._name = name
self._client = client.request_queue(self._id, client_key=self._client_key)
self._config = Configuration.get_global_configuration() # We always use the global config
Copy link
Member

Choose a reason for hiding this comment

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

Is this actually used anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, good point. It's not needed in the simplified storage manager version since it will use the global config if you don't provide config instance anyway.

"""
if request is None:
logging.debug(f'Cannot find a request from the beginning of queue, will be retried later. nextRequestId: {next_request_id}')
asyncio.get_event_loop().call_later(STORAGE_CONSISTENCY_DELAY_MILLIS // 1000, lambda: self._in_progress.remove(next_request_id))
Copy link
Member

Choose a reason for hiding this comment

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

Why not asyncio.get_running_loop()? It's recommended over get_event_loop().

Suggested change
asyncio.get_event_loop().call_later(STORAGE_CONSISTENCY_DELAY_MILLIS // 1000, lambda: self._in_progress.remove(next_request_id))
asyncio.get_running_loop().call_later(STORAGE_CONSISTENCY_DELAY_MILLIS // 1000, lambda: self._in_progress.remove(next_request_id))

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice, did not know that

# Performance optimization: add request straight to head if possible
self._maybe_add_request_to_queue_head(request['id'], forefront)

asyncio.get_event_loop().call_later(STORAGE_CONSISTENCY_DELAY_MILLIS // 1000, callback)
Copy link
Member

Choose a reason for hiding this comment

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

Same with the get_running_loop()

Suggested change
asyncio.get_event_loop().call_later(STORAGE_CONSISTENCY_DELAY_MILLIS // 1000, callback)
asyncio.get_running_loop().call_later(STORAGE_CONSISTENCY_DELAY_MILLIS // 1000, callback)

@jirimoravcik jirimoravcik merged commit c6cad34 into master Jan 24, 2023
@jirimoravcik jirimoravcik deleted the feature/request-queue-class branch January 24, 2023 10:35
@fnesveda fnesveda added the validated Issues that are resolved and their solutions fulfill the acceptance criteria. label Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t-core-services Issues with this label are in the ownership of the platform team. validated Issues that are resolved and their solutions fulfill the acceptance criteria.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.