feat: fetch views manually and worker
This commit is contained in:
@@ -11,7 +11,6 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def update_views_manually(self: 'Usecase', input: dto.UpdateViewsManuallyInput) -> dto.PurchaseOutput:
|
||||
"""Ручное обновление просмотров для закупа."""
|
||||
async with self.database.transaction():
|
||||
purchase = await self.database.get_purchase(input.user_id, input.purchase_id)
|
||||
if not purchase:
|
||||
@@ -20,13 +19,11 @@ async def update_views_manually(self: 'Usecase', input: dto.UpdateViewsManuallyI
|
||||
|
||||
fetched_at = datetime.datetime.now(datetime.UTC)
|
||||
|
||||
# Обновляем метрики закупа
|
||||
purchase.views_count = input.views_count
|
||||
purchase.views_availability = domain.PostViewsAvailability.MANUAL
|
||||
purchase.last_views_fetch_at = fetched_at
|
||||
await self.database.update_purchase(purchase)
|
||||
|
||||
# Создаём снимок
|
||||
snapshot = domain.ViewsSnapshot(
|
||||
purchase_id=purchase.id,
|
||||
views_count=input.views_count,
|
||||
@@ -36,7 +33,6 @@ async def update_views_manually(self: 'Usecase', input: dto.UpdateViewsManuallyI
|
||||
|
||||
log.info('Views manually updated for purchase %s: %d', purchase.id, input.views_count)
|
||||
|
||||
# Возвращаем обновлённый закуп
|
||||
return dto.PurchaseOutput(
|
||||
id=purchase.id,
|
||||
target_channel_id=purchase.target_channel_id,
|
||||
|
||||
Reference in New Issue
Block a user