Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
121 lines
5.1 KiB
Python
121 lines
5.1 KiB
Python
"""Unattended channel-runner persistence — one row per run, one per clip.
|
|
|
|
The channel runner drives faceless, unattended matrices: a source list is
|
|
expanded (``domains.series.fanout``) into de-duplicated render+publish specs,
|
|
each rendered as a normal ReelForge job and later cross-posted with per-account
|
|
pacing. Two additive tables record that work so a later run can DEDUPE against
|
|
what already rendered (``ChannelClip.spec_hash``) and the publish-scheduler can
|
|
find COMPLETE-but-unpublished clips.
|
|
|
|
* :class:`ChannelRun` — bookkeeping for one runner pass (who / which channel /
|
|
the serialized :class:`ChannelRunConfig`).
|
|
* :class:`ChannelClip` — one rendered clip: its content ``spec_hash`` (the
|
|
cross-run dedupe authority), the owning ``job_id``, the target ``account`` /
|
|
``platform``, a lifecycle ``status`` and, once queued to publish, the
|
|
``scheduled_publish_id`` linking to ``scheduled_publish``.
|
|
|
|
Registered on ``Base.metadata`` via ``migrations/env.py`` (and the repository /
|
|
runner import chain). Every additive non-null column carries a ``server_default``
|
|
so an autogenerated migration never breaks existing rows (repo rule).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import (
|
|
DateTime,
|
|
ForeignKey,
|
|
String,
|
|
func,
|
|
text,
|
|
)
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.models.db.base import Base, jsonb_variant
|
|
|
|
#: Clip lifecycle states.
|
|
CLIP_STATUS_PENDING = "pending" # rendered (job created), not yet scheduled to publish
|
|
CLIP_STATUS_SCHEDULED = "scheduled" # a ScheduledPublish row now owns the cross-post
|
|
CLIP_STATUS_FAILED = "failed" # the render enqueue was reconciled (never published)
|
|
|
|
|
|
def _uuid() -> str:
|
|
return uuid.uuid4().hex
|
|
|
|
|
|
class ChannelRun(Base):
|
|
"""One unattended runner pass over a channel's source list."""
|
|
|
|
__tablename__ = "channel_runs"
|
|
|
|
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=_uuid)
|
|
user_id: Mapped[str] = mapped_column(
|
|
ForeignKey("users.id"), index=True, nullable=False
|
|
)
|
|
channel_id: Mapped[str] = mapped_column(String(64), index=True, nullable=False)
|
|
# Serialized ChannelRunConfig view (grows without a migration). Always
|
|
# runner-generated (never client input) and written on every insert via
|
|
# ``ChannelRunRepository.create`` as ``dict(params or {})`` — so it is NOT
|
|
# NULL and carries an empty-object ``server_default`` like every other
|
|
# non-null column on this table (repo rule). ``jsonb_variant`` renders JSONB
|
|
# on PostgreSQL (has ``=`` so the server-default drift check runs) and plain
|
|
# JSON elsewhere, matching ``media_jobs`` JSON-dict columns.
|
|
params: Mapped[dict] = mapped_column(
|
|
jsonb_variant(),
|
|
default=dict,
|
|
server_default=text("'{}'"),
|
|
nullable=False,
|
|
)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), server_default=func.now(), index=True, nullable=False
|
|
)
|
|
|
|
|
|
class ChannelClip(Base):
|
|
"""One rendered clip produced by a runner pass.
|
|
|
|
``spec_hash`` is the account-scoped fan-out content hash — the cross-run
|
|
dedupe authority. It is indexed so ``seen_hashes(channel_id)`` is an O(index)
|
|
scan and a duplicate combination is never rendered twice.
|
|
"""
|
|
|
|
__tablename__ = "channel_clips"
|
|
|
|
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=_uuid)
|
|
channel_id: Mapped[str] = mapped_column(String(64), index=True, nullable=False)
|
|
# ``run_id`` is the runner-generated identity for one pass. It groups the
|
|
# clips of a pass, but it is NOT a ``channel_runs`` primary key: the runner
|
|
# writes clips *during* the pass while the ``channel_runs`` bookkeeping row
|
|
# (a separate uuid) is persisted afterwards — and the worker path writes no
|
|
# ``channel_runs`` row at all. A hard FK to ``channel_runs.id`` could never
|
|
# be satisfied on Postgres (it only appeared to work under SQLite, where FKs
|
|
# are off by default). Keep it an indexed correlation string.
|
|
run_id: Mapped[str] = mapped_column(String(32), index=True, nullable=False)
|
|
# Account-scoped fan-out content hash (16-hex). The dedupe authority.
|
|
spec_hash: Mapped[str] = mapped_column(String(32), index=True, nullable=False)
|
|
job_id: Mapped[str] = mapped_column(
|
|
ForeignKey("jobs.id"), index=True, nullable=False
|
|
)
|
|
account: Mapped[str] = mapped_column(
|
|
String(64), default="", server_default=text("''"), nullable=False
|
|
)
|
|
platform: Mapped[str] = mapped_column(
|
|
String(32), default="", server_default=text("''"), nullable=False
|
|
)
|
|
status: Mapped[str] = mapped_column(
|
|
String(20),
|
|
default=CLIP_STATUS_PENDING,
|
|
server_default=text("'pending'"),
|
|
index=True,
|
|
nullable=False,
|
|
)
|
|
# Set once the clip is queued to auto-publish (links to ``scheduled_publish``).
|
|
scheduled_publish_id: Mapped[str | None] = mapped_column(
|
|
String(32), nullable=True
|
|
)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), server_default=func.now(), index=True, nullable=False
|
|
)
|