remove processing on fail, added clear failed
This commit is contained in:
1 parent
1cdb2a5e9c
commit
81f8bc26e3
3 files changed
+38
-19
No files matched your search
+22
-15
@@ -1,6 +1,6 @@
|
||||
// proxer-queue-worker.js
|
||||
const { exec } = require("child_process");
|
||||
const { spawn } = require('child_process');
|
||||
const { spawn } = require("child_process");
|
||||
const { MongoClient } = require("mongodb");
|
||||
const path = require("path");
|
||||
require("dotenv").config();
|
||||
@@ -34,21 +34,23 @@ async function runJob(job) {
|
||||
const cmd = [
|
||||
process.env.VENV_PYTHON,
|
||||
path.join(__dirname, "scripts/proxer-dl-video.py"),
|
||||
"-u", job.url,
|
||||
"-f", job.filename,
|
||||
"-t", job.token,
|
||||
"-o", process.env.OUTPUT_DIR
|
||||
"-u",
|
||||
job.url,
|
||||
"-f",
|
||||
job.filename,
|
||||
"-t",
|
||||
job.token,
|
||||
"-o",
|
||||
process.env.OUTPUT_DIR,
|
||||
];
|
||||
|
||||
const proc = spawn(cmd[0], cmd.slice(1));
|
||||
|
||||
let output = "";
|
||||
proc.stdout.on("data", d => output += d.toString());
|
||||
proc.stderr.on("data", d => output += d.toString());
|
||||
proc.stdout.on("data", (d) => (output += d.toString()));
|
||||
proc.stderr.on("data", (d) => (output += d.toString()));
|
||||
|
||||
const exitCode = await new Promise(resolve =>
|
||||
proc.on("close", resolve)
|
||||
);
|
||||
const exitCode = await new Promise((resolve) => proc.on("close", resolve));
|
||||
|
||||
// ========== CAPTCHA / ERROR DETECTION ==========
|
||||
const suspicious =
|
||||
@@ -58,14 +60,21 @@ async function runJob(job) {
|
||||
output.toLowerCase().includes("blocked") ||
|
||||
output.toLowerCase().includes("token") ||
|
||||
output.toLowerCase().includes("forbidden");
|
||||
|
||||
if (suspicious) {
|
||||
console.log("⛔ CAPTCHA or fatal error detected, notifying system");
|
||||
console.log(output)
|
||||
console.log(output);
|
||||
await failedCol.insertOne({
|
||||
filename: job.filename,
|
||||
failed_at: new Date(),
|
||||
output_log: output
|
||||
output_log: output,
|
||||
});
|
||||
|
||||
// Unset the processing flag so the job isn't stuck
|
||||
await queueCol.updateOne(
|
||||
{ _id: job._id },
|
||||
{ $unset: { processing: "" } }
|
||||
);
|
||||
return true; // signals worker to halt globally
|
||||
}
|
||||
|
||||
@@ -73,19 +82,17 @@ async function runJob(job) {
|
||||
await doneCol.insertOne({
|
||||
filename: job.filename,
|
||||
finished_at: new Date(),
|
||||
output_log: output
|
||||
output_log: output,
|
||||
});
|
||||
|
||||
await queueCol.deleteOne({ _id: job._id });
|
||||
return false;
|
||||
|
||||
} catch (err) {
|
||||
console.error("Worker crash:", err);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ========================
|
||||
// MAIN LOOP
|
||||
// ========================
|
||||
|
||||
+13
-4
@@ -30,10 +30,19 @@ router.get("/status-data", queue.statusData);
|
||||
// =======================
|
||||
router.post("/clear-captcha", async (req, res) => {
|
||||
const db = await getDb();
|
||||
await db.collection("settings").updateOne(
|
||||
{ _id: "global" },
|
||||
{ $set: { captcha_blocked: false } }
|
||||
);
|
||||
await db
|
||||
.collection("settings")
|
||||
.updateOne({ _id: "global" }, { $set: { captcha_blocked: false } });
|
||||
// Redirect to status, controller fetches everything
|
||||
res.redirect("/status");
|
||||
});
|
||||
|
||||
router.post("/clear-failed", async (req, res) => {
|
||||
const db = await getDb();
|
||||
await db
|
||||
.collection("failed")
|
||||
.deleteMany({}) //delete all
|
||||
|
||||
// Redirect to status, controller fetches everything
|
||||
res.redirect("/status");
|
||||
});
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
<nav class="d-flex gap-2">
|
||||
<a class="btn btn-outline-light" href="/">Home</a>
|
||||
<a class="btn btn-outline-light" href="/status">Status</a>
|
||||
<form id="clear-failed-form" action="/clear-failed" method="POST" class="d-inline ms-2">
|
||||
<button class="btn btn-warning">🗑 Clear Failed</button>
|
||||
</form>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
|
||||
Reference in new issue
Block a user