Files
campus_spider/app/core/id_gen.py
T
2026-07-24 18:42:37 +08:00

15 lines
346 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""雪花 ID 生成
全项目共用一个生成器实例。instance 号用于区分不同服务,
避免多端 ID 冲突(job_cleaner 已占用 1、2spider 用 3)。
"""
from snowflake import SnowflakeGenerator
_id_gen = SnowflakeGenerator(instance=3)
def next_id() -> int:
"""生成下一个雪花 ID"""
return next(_id_gen)