update last seen property when processing listings to refresh data
This commit is contained in:
parent
480957dc72
commit
526f4fc0c3
2 changed files with 12 additions and 0 deletions
|
|
@ -17,9 +17,11 @@ logger = logging.getLogger("uvicorn.error")
|
||||||
class ListingProcessor:
|
class ListingProcessor:
|
||||||
semaphore: asyncio.Semaphore
|
semaphore: asyncio.Semaphore
|
||||||
process_steps: list[Step]
|
process_steps: list[Step]
|
||||||
|
listing_repository: ListingRepository
|
||||||
|
|
||||||
def __init__(self, listing_repository: ListingRepository):
|
def __init__(self, listing_repository: ListingRepository):
|
||||||
self.semaphore = asyncio.Semaphore(20)
|
self.semaphore = asyncio.Semaphore(20)
|
||||||
|
self.listing_repository = listing_repository
|
||||||
# Register new processing steps here
|
# Register new processing steps here
|
||||||
# Order is important
|
# Order is important
|
||||||
self.process_steps = [
|
self.process_steps = [
|
||||||
|
|
@ -29,6 +31,7 @@ class ListingProcessor:
|
||||||
]
|
]
|
||||||
|
|
||||||
async def process_listing(self, listing_id: int) -> Listing | None:
|
async def process_listing(self, listing_id: int) -> Listing | None:
|
||||||
|
await self.listing_repository.mark_seen(listing_id)
|
||||||
listing = None
|
listing = None
|
||||||
for step in self.process_steps:
|
for step in self.process_steps:
|
||||||
if await step.needs_processing(listing_id):
|
if await step.needs_processing(listing_id):
|
||||||
|
|
|
||||||
|
|
@ -193,3 +193,12 @@ class ListingRepository:
|
||||||
)
|
)
|
||||||
|
|
||||||
return model_listing
|
return model_listing
|
||||||
|
|
||||||
|
async def mark_seen(self, listing_id: int) -> None:
|
||||||
|
listings = await self.get_listings(only_ids=[listing_id])
|
||||||
|
if len(listings) == 0:
|
||||||
|
return
|
||||||
|
listing = listings[0]
|
||||||
|
now = datetime.now()
|
||||||
|
listing.last_seen = now
|
||||||
|
await self.upsert_listings([listing])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue