(task)
| 43 | } |
| 44 | |
| 45 | async function onTaskStart(task) { |
| 46 | if (!task.isProcessing || task.batchesDone >= task.batchCount) { |
| 47 | return |
| 48 | } |
| 49 | |
| 50 | if (typeof task.startTime !== "number") { |
| 51 | task.startTime = Date.now() |
| 52 | } |
| 53 | if (!("instances" in task)) { |
| 54 | task["instances"] = [] |
| 55 | } |
| 56 | |
| 57 | task["stopTask"].innerHTML = '<i class="fa-solid fa-circle-stop"></i> Stop' |
| 58 | task["taskStatusLabel"].innerText = "Starting" |
| 59 | task["taskStatusLabel"].classList.add("waitingTaskLabel") |
| 60 | |
| 61 | if (task.previewTaskReq !== undefined) { |
| 62 | let controlImagePreview = task.taskConfig.querySelector(".controlnet-img-preview > img") |
| 63 | try { |
| 64 | let result = await SD.filter(task.previewTaskReq) |
| 65 | |
| 66 | controlImagePreview.src = result.output[0] |
| 67 | let controlImageLargePreview = task.taskConfig.querySelector( |
| 68 | ".controlnet-img-preview .task-fs-initimage img" |
| 69 | ) |
| 70 | controlImageLargePreview.src = controlImagePreview.src |
| 71 | } catch (error) { |
| 72 | console.log("filter error", error) |
| 73 | } |
| 74 | |
| 75 | delete task.previewTaskReq |
| 76 | } |
| 77 | |
| 78 | let newTaskReqBody = task.reqBody |
| 79 | if (task.batchCount > 1) { |
| 80 | // Each output render batch needs it's own task reqBody instance to avoid altering the other runs after they are completed. |
| 81 | newTaskReqBody = Object.assign({}, task.reqBody) |
| 82 | if (task.batchesDone == task.batchCount - 1) { |
| 83 | // Last batch of the task |
| 84 | // If the number of parallel jobs is no factor of the total number of images, the last batch must create less than "parallel jobs count" images |
| 85 | // E.g. with numOutputsTotal = 6 and num_outputs = 5, the last batch shall only generate 1 image. |
| 86 | newTaskReqBody.num_outputs = task.numOutputsTotal - task.reqBody.num_outputs * (task.batchCount - 1) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | const startSeed = task.seed || newTaskReqBody.seed |
| 91 | const genSeeds = Boolean( |
| 92 | typeof newTaskReqBody.seed !== "number" || (newTaskReqBody.seed === task.seed && task.numOutputsTotal > 1) |
| 93 | ) |
| 94 | if (genSeeds) { |
| 95 | newTaskReqBody.seed = parseInt(startSeed) + task.batchesDone * task.reqBody.num_outputs |
| 96 | } |
| 97 | |
| 98 | const outputContainer = document.createElement("div") |
| 99 | outputContainer.className = "img-batch" |
| 100 | task.outputContainer.insertBefore(outputContainer, task.outputContainer.firstChild) |
| 101 | |
| 102 | const eventInfo = { reqBody: newTaskReqBody } |
no test coverage detected