From 0cc8f06e86f0e7cccc52a720ff770f7ac13b1f69 Mon Sep 17 00:00:00 2001 From: yezi Date: Wed, 28 Feb 2024 06:40:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E7=AE=80=E4=B9=A6?= =?UTF-8?q?=E5=A4=A7=E8=BD=AC=E7=9B=98=E6=8A=BD=E5=A5=96=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81=20record=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jobs/fetch_jianshu_lottery_win_records.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/jobs/fetch_jianshu_lottery_win_records.py b/jobs/fetch_jianshu_lottery_win_records.py index 02acdd2..70d70bd 100644 --- a/jobs/fetch_jianshu_lottery_win_records.py +++ b/jobs/fetch_jianshu_lottery_win_records.py @@ -5,7 +5,7 @@ from jkit.jianshu_lottery import JianshuLottery, JianshuLotteryWinRecord from prefect import flow, get_run_logger from prefect.states import Completed, State -from pymongo import DESCENDING +from pymongo import ASCENDING, DESCENDING, IndexModel from utils.config_generators import generate_deployment_config, generate_flow_config from utils.db import DB @@ -26,7 +26,7 @@ class UserInfoField(Field, **FIELD_OBJECT_CONFIG): class JianshuLotteryWinRecordDocument(Documemt, **DOCUMENT_OBJECT_CONFIG): - _id: PositiveInt # type: ignore + record_id: PositiveInt time: datetime award_name: str user_info: UserInfoField @@ -40,12 +40,12 @@ async def get_latest_stored_record_id() -> int: except StopAsyncIteration: return 0 - return latest_data._id + return latest_data.record_id def process_item(item: JianshuLotteryWinRecord, /) -> JianshuLotteryWinRecordDocument: return JianshuLotteryWinRecordDocument( - _id=item.id, + record_id=item.id, time=item.time, award_name=item.award_name, user_info=UserInfoField( @@ -62,6 +62,10 @@ def process_item(item: JianshuLotteryWinRecord, /) -> JianshuLotteryWinRecordDoc ) ) async def flow_func() -> State: + await COLLECTION.create_indexes( + [IndexModel([("recordId", ASCENDING)], unique=True)] + ) + logger = get_run_logger() stop_id = await get_latest_stored_record_id()