Fix immediate automation pause, restored queue rendering and bounded disk reads; release 2.1.75
CI / verify (push) Canceled after 0s

This commit is contained in:
Sucukdeluxe committed 2026-10-20 13:56:04 +02:00
1 parent 267a840853
commit 80eb878f1b
12 files changed
+168 -68

No files matched your search

+39 -14
View File
@@ -1,23 +1,48 @@
const fs = require('node:fs');
const { runtimePerformance } = require('./performance-monitor');
const Semaphore = require('./semaphore');
const statUploadFile = file => runtimePerformance.measure('file.stat', () => fs.promises.stat(file));
async function* readUploadFile(file, signal) {
signal?.throwIfAborted();
const stream = fs.createReadStream(file, { highWaterMark: 1024 * 1024, ...(signal ? { signal } : {}) });
const iterator = stream[Symbol.asyncIterator]();
try {
for (;;) {
const result = await runtimePerformance.measure('file.read', () => iterator.next());
if (result.done) break;
function createUploadFileReader({ limit = 4, open = file => fs.promises.open(file, 'r') } = {}) {
const slots = new Semaphore(limit);
const admitted = async (signal, action) => {
await runtimePerformance.measure('file.read.wait', () => slots.acquire(signal));
try {
signal?.throwIfAborted();
yield result.value;
return await action();
} finally {
slots.release();
}
} finally {
stream.destroy();
await iterator.return?.();
}
};
return {
snapshot: () => ({ limit: slots.limit, active: slots.active, waiting: slots.pending }),
updateLimit(value) {
if (!Number.isInteger(value) || value < 1 || value > 32) throw new Error('Ungültiges Lese-Limit.');
slots.updateLimit(value);
return this.snapshot();
},
async *read(file, signal) {
signal?.throwIfAborted();
const handle = await admitted(signal, () => open(file));
try {
for (;;) {
const buffer = Buffer.allocUnsafe(1024 * 1024);
const result = await admitted(signal, () => runtimePerformance.measure('file.read', () => handle.read(buffer, 0, buffer.length, null)));
signal?.throwIfAborted();
if (!result.bytesRead) break;
yield buffer.subarray(0, result.bytesRead);
}
} finally {
await handle.close();
}
}
};
}
module.exports = { statUploadFile, readUploadFile };
const uploadFileReader = createUploadFileReader();
const readUploadFile = (file, signal) => uploadFileReader.read(file, signal);
const getUploadReadSnapshot = () => uploadFileReader.snapshot();
const setUploadReadLimit = value => uploadFileReader.updateLimit(value);
module.exports = { statUploadFile, readUploadFile, getUploadReadSnapshot, setUploadReadLimit, createUploadFileReader };