feat: schedule periodic reports asynchronously
This commit is contained in:
@@ -108,6 +108,8 @@ class PeriodicReport(Base):
|
||||
UniqueConstraint("user_id", "report_type", "period_start", "period_end", name="uq_sys_periodic_report_period"),
|
||||
Index("ix_sys_periodic_report_user_type_created", "user_id", "report_type", "created_at"),
|
||||
Index("ix_sys_periodic_report_status_created", "status", "created_at"),
|
||||
Index("ix_periodic_report_job_due", "status", "next_run_at", "id"),
|
||||
Index("ix_periodic_report_job_stale", "status", "locked_at"),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(PRIMARY_KEY_TYPE, primary_key=True, autoincrement=True)
|
||||
@@ -123,6 +125,13 @@ class PeriodicReport(Base):
|
||||
status: Mapped[str] = mapped_column(String(20), default="success", index=True, nullable=False)
|
||||
error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
generated_by: Mapped[str] = mapped_column(String(30), default="manual", nullable=False)
|
||||
attempt_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
max_attempts: Mapped[int] = mapped_column(Integer, default=3, nullable=False)
|
||||
next_run_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
locked_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
locked_by: Mapped[str | None] = mapped_column(String(120), nullable=True)
|
||||
last_started_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
finished_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
generated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), nullable=False)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now(), nullable=False)
|
||||
|
||||
Reference in New Issue
Block a user