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
|
// proxer-queue-worker.js
|
||||||
const { exec } = require("child_process");
|
const { exec } = require("child_process");
|
||||||
const { spawn } = require('child_process');
|
const { spawn } = require("child_process");
|
||||||
const { MongoClient } = require("mongodb");
|
const { MongoClient } = require("mongodb");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
@@ -34,21 +34,23 @@ async function runJob(job) {
|
|||||||
const cmd = [
|
const cmd = [
|
||||||
process.env.VENV_PYTHON,
|
process.env.VENV_PYTHON,
|
||||||
path.join(__dirname, "scripts/proxer-dl-video.py"),
|
path.join(__dirname, "scripts/proxer-dl-video.py"),
|
||||||
"-u", job.url,
|
"-u",
|
||||||
"-f", job.filename,
|
job.url,
|
||||||
"-t", job.token,
|
"-f",
|
||||||
"-o", process.env.OUTPUT_DIR
|
job.filename,
|
||||||
|
"-t",
|
||||||
|
job.token,
|
||||||
|
"-o",
|
||||||
|
process.env.OUTPUT_DIR,
|
||||||
];
|
];
|
||||||
|
|
||||||
const proc = spawn(cmd[0], cmd.slice(1));
|
const proc = spawn(cmd[0], cmd.slice(1));
|
||||||
|
|
||||||
let output = "";
|
let output = "";
|
||||||
proc.stdout.on("data", d => output += d.toString());
|
proc.stdout.on("data", (d) => (output += d.toString()));
|
||||||
proc.stderr.on("data", d => output += d.toString());
|
proc.stderr.on("data", (d) => (output += d.toString()));
|
||||||
|
|
||||||
const exitCode = await new Promise(resolve =>
|
const exitCode = await new Promise((resolve) => proc.on("close", resolve));
|
||||||
proc.on("close", resolve)
|
|
||||||
);
|
|
||||||
|
|
||||||
// ========== CAPTCHA / ERROR DETECTION ==========
|
// ========== CAPTCHA / ERROR DETECTION ==========
|
||||||
const suspicious =
|
const suspicious =
|
||||||
@@ -58,14 +60,21 @@ async function runJob(job) {
|
|||||||
output.toLowerCase().includes("blocked") ||
|
output.toLowerCase().includes("blocked") ||
|
||||||
output.toLowerCase().includes("token") ||
|
output.toLowerCase().includes("token") ||
|
||||||
output.toLowerCase().includes("forbidden");
|
output.toLowerCase().includes("forbidden");
|
||||||
|
|
||||||
if (suspicious) {
|
if (suspicious) {
|
||||||
console.log("⛔ CAPTCHA or fatal error detected, notifying system");
|
console.log("⛔ CAPTCHA or fatal error detected, notifying system");
|
||||||
console.log(output)
|
console.log(output);
|
||||||
await failedCol.insertOne({
|
await failedCol.insertOne({
|
||||||
filename: job.filename,
|
filename: job.filename,
|
||||||
failed_at: new Date(),
|
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
|
return true; // signals worker to halt globally
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,19 +82,17 @@ async function runJob(job) {
|
|||||||
await doneCol.insertOne({
|
await doneCol.insertOne({
|
||||||
filename: job.filename,
|
filename: job.filename,
|
||||||
finished_at: new Date(),
|
finished_at: new Date(),
|
||||||
output_log: output
|
output_log: output,
|
||||||
});
|
});
|
||||||
|
|
||||||
await queueCol.deleteOne({ _id: job._id });
|
await queueCol.deleteOne({ _id: job._id });
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Worker crash:", err);
|
console.error("Worker crash:", err);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ========================
|
// ========================
|
||||||
// MAIN LOOP
|
// MAIN LOOP
|
||||||
// ========================
|
// ========================
|
||||||
|
|||||||
+13
-4
@@ -30,10 +30,19 @@ router.get("/status-data", queue.statusData);
|
|||||||
// =======================
|
// =======================
|
||||||
router.post("/clear-captcha", async (req, res) => {
|
router.post("/clear-captcha", async (req, res) => {
|
||||||
const db = await getDb();
|
const db = await getDb();
|
||||||
await db.collection("settings").updateOne(
|
await db
|
||||||
{ _id: "global" },
|
.collection("settings")
|
||||||
{ $set: { captcha_blocked: false } }
|
.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
|
// Redirect to status, controller fetches everything
|
||||||
res.redirect("/status");
|
res.redirect("/status");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,6 +26,9 @@
|
|||||||
<nav class="d-flex gap-2">
|
<nav class="d-flex gap-2">
|
||||||
<a class="btn btn-outline-light" href="/">Home</a>
|
<a class="btn btn-outline-light" href="/">Home</a>
|
||||||
<a class="btn btn-outline-light" href="/status">Status</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>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user