perf(douyu): 拆分任务槽并改造绑定扫码调度
This commit is contained in:
@@ -360,6 +360,18 @@ class DouyuTask(Base):
|
||||
UTCDateTime, default=_utcnow, index=True
|
||||
)
|
||||
finished_at: Mapped[datetime | None] = mapped_column(UTCDateTime, nullable=True)
|
||||
# Durable background scheduling. Waiting work is not an active worker.
|
||||
queue_lane: Mapped[str] = mapped_column(
|
||||
String(32), nullable=False, default="", server_default=""
|
||||
)
|
||||
next_run_at: Mapped[datetime | None] = mapped_column(UTCDateTime, nullable=True)
|
||||
run_deadline_at: Mapped[datetime | None] = mapped_column(
|
||||
UTCDateTime, nullable=True
|
||||
)
|
||||
last_run_at: Mapped[datetime | None] = mapped_column(UTCDateTime, nullable=True)
|
||||
attempt_count: Mapped[int] = mapped_column(
|
||||
Integer, nullable=False, default=0, server_default="0"
|
||||
)
|
||||
platform_task_id: Mapped[int | None] = mapped_column(
|
||||
BigInteger,
|
||||
nullable=True,
|
||||
@@ -369,6 +381,19 @@ class DouyuTask(Base):
|
||||
account_assigned_to: Mapped[int | None] = mapped_column(
|
||||
ForeignKey("users.id"), nullable=True
|
||||
)
|
||||
# One active QR task per fulfillment session, enforced by MySQL even when
|
||||
# two application workers race through the row lock boundary.
|
||||
active_binding_key: Mapped[str | None] = mapped_column(
|
||||
String(64),
|
||||
Computed(
|
||||
"CASE WHEN task_type = 'get_bind_qr' "
|
||||
"AND platform_task_id IS NOT NULL "
|
||||
"AND status IN ('planned', 'pending', 'running') "
|
||||
"THEN CONCAT('bind:', platform_task_id) ELSE NULL END",
|
||||
persisted=True,
|
||||
),
|
||||
nullable=True,
|
||||
)
|
||||
|
||||
__table_args__ = (
|
||||
Index(
|
||||
@@ -388,6 +413,18 @@ class DouyuTask(Base):
|
||||
"handbook_scope",
|
||||
"id",
|
||||
),
|
||||
Index(
|
||||
"ix_douyu_tasks_lane_due",
|
||||
"queue_lane",
|
||||
"status",
|
||||
"next_run_at",
|
||||
"id",
|
||||
),
|
||||
Index(
|
||||
"uq_douyu_tasks_active_binding",
|
||||
"active_binding_key",
|
||||
unique=True,
|
||||
),
|
||||
)
|
||||
|
||||
account: Mapped[Account] = relationship("Account", back_populates="douyu_tasks")
|
||||
|
||||
Reference in New Issue
Block a user