Skip to content
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

feat: Various fixes and improvements #41

Merged
merged 5 commits into from
Jan 31, 2023

Conversation

jirimoravcik
Copy link
Member

@jirimoravcik jirimoravcik commented Jan 30, 2023

Fixes:

  • removed tons of todos that I either validated (e.g. vs crawlee) or removed since they're not really relevant
  • env var for local storage directory now properly handled, also added a test
  • validation of request queue's request dict via budget ow
  • LRUCache change yield from to return, narrow return type
  • memory storage tests: removed write_metadata=True since it's not the default and reworked the tests to work without metadata.

Improvements:

  • added some more cases in various tests
  • added an e2e test that simulates 2 local runs. First run uses local storage to create files, second run reads from them. Basically checks if rerunning the actor locally works as intended.

@jirimoravcik jirimoravcik changed the title Feature/fixes and improvements feat: Various fixes and improvements Jan 30, 2023
@github-actions github-actions bot added this to the 56th sprint - Platform team milestone Jan 30, 2023
@github-actions github-actions bot added the t-platform Issues with this label are in the ownership of the platform team. label Jan 30, 2023
@jirimoravcik jirimoravcik added the adhoc Ad-hoc unplanned task added during the sprint. label Jan 30, 2023
@jirimoravcik jirimoravcik requested review from fnesveda and drobnikj and removed request for fnesveda January 30, 2023 18:55
...


def _budget_ow(
Copy link
Member

Choose a reason for hiding this comment

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

I guess, there should be some dynamic type checker in python. But I like the name maybe you should create package of it 😄

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.

Cool! Just a few small comments 🙂



@overload
def _budget_ow(value: Union[str, int, float, bool], predicate: Tuple[Type, bool], value_name: str) -> None: # noqa: U100
Copy link
Member

Choose a reason for hiding this comment

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

😄 😄 great name

def validate_single(field_value: Any, expected_type: Type, required: bool, name: str) -> None:
if field_value is None and required:
raise ValueError(f'"{name}" is required!')
actual_type = type(field_value)
Copy link
Member

Choose a reason for hiding this comment

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

I think this is too strict, it won't work for subclasses for example. I'd rather use isinstance here.

self._datasets_directory = os.path.join(self._local_data_directory, 'datasets')
self._key_value_stores_directory = os.path.join(self._local_data_directory, 'key_value_stores')
self._request_queues_directory = os.path.join(self._local_data_directory, 'request_queues')
self._write_metadata = write_metadata if write_metadata is not None else '*' in os.getenv('DEBUG', '')
self._persist_storage = persist_storage if persist_storage is not None else not any(
os.getenv('APIFY_PERSIST_STORAGE', 'true') == s for s in ['false', '0', ''])
os.getenv(ApifyEnvVars.PERSIST_STORAGE, 'true') == s for s in ['false', '0', ''])
Copy link
Member

Choose a reason for hiding this comment

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

You could use _maybe_parse_bool here

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, code will be nicer

from apify.storages import StorageManager


async def run_e2e_test(monkeypatch: pytest.MonkeyPatch, tmp_path: str, purge_on_start: bool = True) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

You could use pytest.mark.parametrize here:

Suggested change
async def run_e2e_test(monkeypatch: pytest.MonkeyPatch, tmp_path: str, purge_on_start: bool = True) -> None:
@pytest.mark.parametrize('purge_on_start', [True, False])
async def test_actor_memory_storage_e2e(monkeypatch: pytest.MonkeyPatch, tmp_path: str, purge_on_start: bool = True) -> None:

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, didn't know that decorator

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.

I wanted to click "Request changes", sorry 😄

@jirimoravcik jirimoravcik requested a review from fnesveda January 31, 2023 18:17
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.

Cool!

@jirimoravcik jirimoravcik merged commit 5bae238 into master Jan 31, 2023
@jirimoravcik jirimoravcik deleted the feature/fixes-and-improvements branch January 31, 2023 19:25
@fnesveda fnesveda added the validated Issues that are resolved and their solutions fulfill the acceptance criteria. label Oct 9, 2023
@github-actions github-actions bot added the tested Temporary label used only programatically for some analytics. label Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adhoc Ad-hoc unplanned task added during the sprint. t-platform Issues with this label are in the ownership of the platform team. tested Temporary label used only programatically for some analytics. 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