Reviewed Input and Output Waiters and improved logging in workers

This commit is contained in:
n1474335 2023-01-18 18:07:06 +00:00
parent 56d1a016da
commit 91f1be8c70
12 changed files with 204 additions and 111 deletions

View file

@ -35,6 +35,14 @@ class BackgroundWorkerWaiter {
log.debug("Registering new background ChefWorker");
this.chefWorker = new ChefWorker();
this.chefWorker.addEventListener("message", this.handleChefMessage.bind(this));
this.chefWorker.postMessage({
action: "setLogPrefix",
data: "BGChefWorker"
});
this.chefWorker.postMessage({
action: "setLogLevel",
data: log.getLevel()
});
let docURL = document.location.href.split(/[#?]/)[0];
const index = docURL.lastIndexOf("/");
@ -52,7 +60,7 @@ class BackgroundWorkerWaiter {
*/
handleChefMessage(e) {
const r = e.data;
log.debug("Receiving '" + r.action + "' from ChefWorker in the background");
log.debug(`Receiving '${r.action}' from BGChefWorker`);
switch (r.action) {
case "bakeComplete":
@ -152,6 +160,18 @@ class BackgroundWorkerWaiter {
this.manager.output.backgroundMagicResult(response.dish.value);
}
/**
* Sets the console log level in the workers.
*/
setLogLevel() {
if (!this.chefWorker) return;
this.chefWorker.postMessage({
action: "setLogLevel",
data: log.getLevel()
});
}
}