Skip to content

Commit

Permalink
Make determine_new method synchronious. Easy API.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vyazovetskov Vladimir committed May 28, 2022
1 parent 6c53541 commit 5bfd989
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "s3-objects-tracker"
version = "0.2.0"
version = "0.3.0"
description = "Track already processed objects inside your s3 bucket."
authors = ["Vladimir Vyazovetskov <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion s3_objects_tracker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from s3_objects_tracker.tracker import S3ObjectsTracker

__version__ = "0.2.0"
__version__ = "0.3.0"

__all__ = ("S3ObjectsTracker",)
2 changes: 1 addition & 1 deletion s3_objects_tracker/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def __aexit__(self, exc_type, exc_val, exc_tb) -> None:
await self._upload_to_s3()
await self._exit_stack.__aexit__(exc_type, exc_val, exc_tb)

async def determine_new(self, objects: List[T]) -> List[T]:
def determine_new(self, objects: List[T]) -> List[T]:
new_objects = []
for _object in objects:
if _object.id not in self._published_ids:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def test_common_workflow(object_storage_mock, s3_credentials):
objects = [Object(i) for i in range(10)]
async with S3ObjectsTracker(**s3_credentials) as tracker:
assert tracker._published_ids == [], "Published IDs should be empty"
new_objects = await tracker.determine_new(objects)
new_objects = tracker.determine_new(objects)
assert new_objects == objects, "New objects should be the same as objects"
for _object in new_objects:
await tracker.publish(_object)
Expand All @@ -35,7 +35,7 @@ async def test_common_workflow(object_storage_mock, s3_credentials):
assert tracker._published_ids == [
_object.id for _object in objects
], "First objects should be published"
new_objects = await tracker.determine_new(next_objects)
new_objects = tracker.determine_new(next_objects)
assert new_objects == next_objects[5:], "Only last 5 objects should be new"
for _object in new_objects:
await tracker.publish(_object)
Expand All @@ -52,15 +52,15 @@ async def test_limit(object_storage_mock, s3_credentials):
objects = [Object(i) for i in range(5)]
async with S3ObjectsTracker(**s3_credentials, max_published_objects=5) as tracker:
assert tracker._published_ids == [], "Published IDs should be empty"
new_objects = await tracker.determine_new(objects)
new_objects = tracker.determine_new(objects)
assert new_objects == objects, "New objects should be the same as objects"
for _object in objects:
await tracker.publish(_object)

next_objects = [Object(i) for i in range(6)]
async with S3ObjectsTracker(**s3_credentials, max_published_objects=5) as tracker:
assert tracker._published_ids == [0, 1, 2, 3, 4], "Objects should be published"
new_objects = await tracker.determine_new(next_objects)
new_objects = tracker.determine_new(next_objects)
assert new_objects == [Object(5)], "Only last _object should be new"
await tracker.publish(new_objects[0])

Expand Down

0 comments on commit 5bfd989

Please sign in to comment.