diff options
author | metamuffin <metamuffin@disroot.org> | 2025-06-02 22:35:33 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-06-02 22:35:33 +0200 |
commit | 5f6dfeada0158c815f0b7b474ec61c18db6af5db (patch) | |
tree | d6109965e7a17549fba5e6fbf96d393db05ab5ed | |
parent | 2b56668dc89d61248fffeb75a6c8d1136aa7fa39 (diff) | |
download | isda-5f6dfeada0158c815f0b7b474ec61c18db6af5db.tar isda-5f6dfeada0158c815f0b7b474ec61c18db6af5db.tar.bz2 isda-5f6dfeada0158c815f0b7b474ec61c18db6af5db.tar.zst |
retry tasks in enqueue worker script
-rw-r--r-- | scripts/config.ts | 3 | ||||
-rw-r--r-- | scripts/enqueue.md | 13 | ||||
-rw-r--r-- | scripts/enqueue.ts | 19 |
3 files changed, 32 insertions, 3 deletions
diff --git a/scripts/config.ts b/scripts/config.ts index 5b5f1da..0662a26 100644 --- a/scripts/config.ts +++ b/scripts/config.ts @@ -12,7 +12,8 @@ export interface Config { } export interface EnqueueTask { - list_file: string + list_file?: string + retry_failed?: boolean, kind: string, interval: number, filter?: string, diff --git a/scripts/enqueue.md b/scripts/enqueue.md index 24ad205..210fb91 100644 --- a/scripts/enqueue.md +++ b/scripts/enqueue.md @@ -5,11 +5,15 @@ Inserts tasks into the queue with some time interval. ## Configuration - `enqueue` - - `list_file`: Path to the task list. The format is described below. (string) + - `list_file`: Path to the task list. The format is described below. (optional + string) + - `retry_failed`: Move failed completed tasks back to the queue instead of + adding from a list file. - `kind`: Task kind to insert. - `interval`: Number of seconds to wait in between inserts. (number) - `filter`: Only inserts tasks that have this flag attached. The flag will be - removed. (optional string) + removed. This filters for fail reason if `retry_failed` is used. (optional + string) - `default_flags`: List of flags attached to every task except where manually removed. (optional list of string) - `data`: Additional attributes that will be attached to the tasks data. @@ -24,6 +28,11 @@ enqueue: data: priority: 100 output: /home/user/somedir + + - retry_failed: true + kind: webpage-download + interval: 86400 + filter: "some_reason" ``` ## Task list file format diff --git a/scripts/enqueue.ts b/scripts/enqueue.ts index be67be7..d2b4729 100644 --- a/scripts/enqueue.ts +++ b/scripts/enqueue.ts @@ -4,6 +4,18 @@ const ws = new WebSocket(Deno.args[0]) let config: Config = {} as unknown as Config async function run_enqueue(eqt: EnqueueTask) { + if (eqt.retry_failed) { + ws.send(JSON.stringify({ + t: "query", + state: "complete", + kind: eqt.kind, + data: eqt.filter ? { failed: eqt.filter } : null, + cookie: "for_enqueue" + })) + return + } + + if (!eqt.list_file) throw new Error("need either list_file or retry_failed"); const file = await Deno.readTextFile(eqt.list_file) for (const line of file.split("\n")) { if (!line.trim().length) continue @@ -58,4 +70,11 @@ ws.onmessage = ev => { if (!started) start() } if (p.t == "error") console.error(`error: ${p.message}`); + if (p.t == "query_response" && p.cookie == "for_enqueue") { + for (const key of p.keys) { + ws.send(JSON.stringify({ t: "metadata", key, data: { failed: null } })) + ws.send(JSON.stringify({ t: "enqueue", key, ignore_complete: true })) + } + ws.send(JSON.stringify({ t: "save" })) + } } |