Show Jellyfin handoff jobs in queue
This commit is contained in:
@@ -647,6 +647,74 @@ class JellyfinSyncJobs:
|
||||
def _copy_job(self, job):
|
||||
return json.loads(json.dumps(job))
|
||||
|
||||
def _queue_job_payload(self, job):
|
||||
config = job.get("config") or {}
|
||||
target_paths = [
|
||||
str(config.get(key) or "").strip()
|
||||
for key in ("jellyfin_tv_dir", "jellyfin_movie_dir")
|
||||
if str(config.get(key) or "").strip()
|
||||
]
|
||||
log_lines = [str(job.get("message") or "")]
|
||||
if job.get("current_file"):
|
||||
log_lines.append(f"Moving: {job['current_file']}")
|
||||
for item in job.get("items") or []:
|
||||
title = str(item.get("title") or item.get("show_id") or "Unknown title")
|
||||
outcome = "moved" if item.get("moved") else str(item.get("reason") or "skipped")
|
||||
target = str(item.get("target") or "").strip()
|
||||
suffix = f" -> {target}" if target else ""
|
||||
log_lines.append(f"{title}: {outcome}{suffix}")
|
||||
payload = self._copy_job(job)
|
||||
payload.update(
|
||||
{
|
||||
"job_type": "jellyfin_handoff",
|
||||
"title": "Jellyfin handoff",
|
||||
"anime_name": "Jellyfin handoff",
|
||||
"mode": "copy",
|
||||
"quality": "library",
|
||||
"episodes": f"{int(job.get('completed') or 0)}/{int(job.get('total') or 0)} entries",
|
||||
"download_dir": str(config.get("download_dir") or ""),
|
||||
"target_dir": ", ".join(target_paths),
|
||||
"exit_code": 1 if job.get("status") == "failed" else None,
|
||||
"log": [line for line in log_lines if line],
|
||||
}
|
||||
)
|
||||
return payload
|
||||
|
||||
def list_queue_jobs(self, limit=50):
|
||||
limit = min(200, max(1, int(limit or 50)))
|
||||
with self.lock, self._connect() as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT payload FROM jellyfin_sync_jobs ORDER BY created_at DESC LIMIT ?",
|
||||
(limit,),
|
||||
).fetchall()
|
||||
return [self._queue_job_payload(self._job_from_row(row)) for row in rows]
|
||||
|
||||
def get_queue_job(self, job_id):
|
||||
with self.lock, self._connect() as conn:
|
||||
row = conn.execute("SELECT payload FROM jellyfin_sync_jobs WHERE id = ?", (job_id,)).fetchone()
|
||||
if row:
|
||||
return self._queue_job_payload(self._job_from_row(row))
|
||||
raise KeyError("Job not found")
|
||||
|
||||
def remove_queue_job(self, job_id):
|
||||
with self.lock:
|
||||
job = self.get_queue_job(job_id)
|
||||
if job["status"] in {"pending", "running"}:
|
||||
raise ValueError("Running Jellyfin handoff jobs cannot be removed")
|
||||
with self._connect() as conn:
|
||||
conn.execute("DELETE FROM jellyfin_sync_jobs WHERE id = ?", (job_id,))
|
||||
return {"ok": True}
|
||||
|
||||
def clear_finished_queue_jobs(self):
|
||||
with self.lock, self._connect() as conn:
|
||||
cursor = conn.execute("DELETE FROM jellyfin_sync_jobs WHERE status IN ('done', 'interrupted')")
|
||||
return {"ok": True, "count": cursor.rowcount}
|
||||
|
||||
def clear_failed_queue_jobs(self):
|
||||
with self.lock, self._connect() as conn:
|
||||
cursor = conn.execute("DELETE FROM jellyfin_sync_jobs WHERE status = 'failed'")
|
||||
return {"ok": True, "count": cursor.rowcount}
|
||||
|
||||
def _find_locked(self, job_id):
|
||||
for job in self.jobs:
|
||||
if job["id"] == job_id:
|
||||
|
||||
Reference in New Issue
Block a user