Skip to content

Commit

Permalink
feat: 调整简书大转盘抽奖记录工作流 record_id
Browse files Browse the repository at this point in the history
  • Loading branch information
FHU-yezi committed Feb 27, 2024
1 parent c1c8284 commit 0cc8f06
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions jobs/fetch_jianshu_lottery_win_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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()
Expand Down

0 comments on commit 0cc8f06

Please sign in to comment.