59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
|
|
from app.timeutil import push_date_from_ts
|
|
|
|
|
|
def test_claim_upload_before_pending_record(temp_db):
|
|
ch = temp_db.create_shorts_channel(name="P", enabled=True)
|
|
day = push_date_from_ts(time.time())
|
|
pending = temp_db.create_shorts_job(
|
|
session_id="",
|
|
room_id="pending1",
|
|
channel_pk=ch["id"],
|
|
push_date=day,
|
|
)
|
|
due = temp_db.create_shorts_job(
|
|
session_id="",
|
|
room_id="due1",
|
|
channel_pk=ch["id"],
|
|
push_date=day,
|
|
)
|
|
temp_db.update_shorts_job(
|
|
due["id"],
|
|
status="scheduled",
|
|
clip_path="/tmp/x.mp4",
|
|
upload_at=time.time() - 10,
|
|
)
|
|
claimed = temp_db.claim_due_shorts_upload()
|
|
assert claimed is not None
|
|
assert claimed["id"] == due["id"]
|
|
assert claimed["status"] == "uploading"
|
|
# pending still pending
|
|
row = temp_db.get_shorts_job(pending["id"])
|
|
assert row["status"] == "pending"
|
|
|
|
|
|
def test_reclaim_stale_uploading(temp_db):
|
|
ch = temp_db.create_shorts_channel(name="S", enabled=True)
|
|
day = push_date_from_ts(time.time())
|
|
job = temp_db.create_shorts_job(
|
|
session_id="",
|
|
room_id="stale1",
|
|
channel_pk=ch["id"],
|
|
push_date=day,
|
|
)
|
|
temp_db.update_shorts_job(
|
|
job["id"],
|
|
status="uploading",
|
|
clip_path="/tmp/x.mp4",
|
|
upload_at=time.time(),
|
|
started_at=time.time() - 500,
|
|
)
|
|
n = temp_db.reclaim_stale_shorts_uploads(max_age_sec=120)
|
|
assert n == 1
|
|
row = temp_db.get_shorts_job(job["id"])
|
|
assert row["status"] == "scheduled"
|