Send web push notifications from worker
This commit is contained in:
parent
3ed06d95bc
commit
03889fe6e2
5 changed files with 267 additions and 1 deletions
|
|
@ -21,6 +21,8 @@ from shlex import quote
|
|||
|
||||
ROOT = Path(__file__).resolve().parent
|
||||
MOVMAKER = ROOT / "movmaker.py"
|
||||
PUSH_SENDER = ROOT / "send_push.js"
|
||||
PUSH_CONFIG = Path.home() / ".config" / "mvlog" / "push.json"
|
||||
STATE_NAME = ".movmaker-state.json"
|
||||
LOCK_NAME = ".movmaker-lock"
|
||||
ENABLED_NAME = ".movmaker-enabled"
|
||||
|
|
@ -125,6 +127,26 @@ def copy_job_from_remote(host: str, job_dir: str, local_input: Path) -> None:
|
|||
raise
|
||||
|
||||
|
||||
def send_push_notification(host: str, remote_root: str, output: str) -> None:
|
||||
if not PUSH_SENDER.exists() or not PUSH_CONFIG.exists():
|
||||
return
|
||||
res = ssh(host, f"cat {remote_q(remote_root + '/cache/push_subscriptions.json')} 2>/dev/null", check=False)
|
||||
if res.returncode != 0 or not res.stdout.strip():
|
||||
return
|
||||
title = output.rsplit('.', 1)[0].replace('_', ' ').title()
|
||||
payload = json.dumps({
|
||||
"title": "New MVLog video",
|
||||
"body": title,
|
||||
"url": "https://bubulescu.org/mvlog/",
|
||||
"tag": f"mvlog-{output}",
|
||||
}, ensure_ascii=False)
|
||||
proc = subprocess.run(["node", str(PUSH_SENDER), str(PUSH_CONFIG), payload], input=res.stdout, text=True, capture_output=True, check=False)
|
||||
if proc.stdout.strip():
|
||||
print(proc.stdout.strip())
|
||||
if proc.stderr.strip():
|
||||
print(proc.stderr.strip(), file=sys.stderr)
|
||||
|
||||
|
||||
def publish_output(host: str, remote_root: str, local_mp4: Path, old_output: str | None) -> str:
|
||||
out_name = local_mp4.name
|
||||
remote_tmp = f"{remote_root}/out-dir/.{out_name}.tmp"
|
||||
|
|
@ -197,6 +219,7 @@ def process_job(host: str, remote_root: str, job: str, work_dir: Path, extra_arg
|
|||
return
|
||||
|
||||
output = publish_output(host, remote_root, local_mp4, old_output)
|
||||
send_push_notification(host, remote_root, output)
|
||||
write_state(host, job_dir, {
|
||||
"status": "done",
|
||||
"fingerprint": fingerprint_after,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue