Worker message with task metadata and CSV options.
Set tracking active task IDs.
Void; posts initial PROGRESS message.
export function handleCsvStart(
message: CSVStartMessage,
activeTasks: Set<string>,
): void {
const { taskId, totalSize, options } = message.payload;
if (activeTasks.has(taskId)) {
console.warn(`[Worker] Task ${taskId} already active, skipping restart`);
return;
}
// Validate file size is not excessively large
if (totalSize > MAX_CSV_SIZE) {
console.error(
`[Worker] CSV file too large: ${totalSize} bytes (max ${MAX_CSV_SIZE})`,
);
globalThis.postMessage({
type: "ERROR",
payload: {
taskId,
error: {
message: `CSV file size (${(totalSize / 1024 / 1024).toFixed(1)}MB) exceeds maximum of ${MAX_CSV_SIZE / 1024 / 1024}MB. Please import a smaller CSV file.`,
name: "CSVSizeExceeded",
},
},
});
return;
}
activeTasks.add(taskId);
const state = {
taskId,
csvBuffer: "", // Buffer for incomplete lines
totalSize,
processedBytes: 0,
defaultStatus: options.defaultStatus ?? "plan_to_read",
startTime: performance.now(),
isComplete: false,
};
csvParserStates.set(taskId, state);
console.debug(
`[Worker] 🚀 Initialized CSV parser for task ${taskId} with defaultStatus=${state.defaultStatus}, totalSize=${totalSize}B, streaming enabled`,
);
globalThis.postMessage({
type: "PROGRESS",
payload: {
taskId,
processedBytes: 0,
totalBytes: totalSize,
},
});
}
Initializes a new CSV parsing task with incremental/streaming parser state. Tracks partial lines across chunks and accumulates parsed rows for progressive output.