(task, reqBody, outputContainer)
| 147 | } |
| 148 | |
| 149 | function getTaskUpdater(task, reqBody, outputContainer) { |
| 150 | const outputMsg = task["outputMsg"] |
| 151 | const progressBar = task["progressBar"] |
| 152 | const progressBarInner = progressBar.querySelector("div") |
| 153 | |
| 154 | const batchCount = task.batchCount |
| 155 | let lastStatus = undefined |
| 156 | return async function (event) { |
| 157 | if (this.status !== lastStatus) { |
| 158 | lastStatus = this.status |
| 159 | switch (this.status) { |
| 160 | case SD.TaskStatus.pending: |
| 161 | task["taskStatusLabel"].innerText = "Pending" |
| 162 | task["taskStatusLabel"].classList.add("waitingTaskLabel") |
| 163 | break |
| 164 | case SD.TaskStatus.waiting: |
| 165 | task["taskStatusLabel"].innerText = "Waiting" |
| 166 | task["taskStatusLabel"].classList.add("waitingTaskLabel") |
| 167 | task["taskStatusLabel"].classList.remove("activeTaskLabel") |
| 168 | break |
| 169 | case SD.TaskStatus.processing: |
| 170 | case SD.TaskStatus.completed: |
| 171 | task["taskStatusLabel"].innerText = "Processing" |
| 172 | task["taskStatusLabel"].classList.add("activeTaskLabel") |
| 173 | task["taskStatusLabel"].classList.remove("waitingTaskLabel") |
| 174 | break |
| 175 | case SD.TaskStatus.stopped: |
| 176 | break |
| 177 | case SD.TaskStatus.failed: |
| 178 | if (!SD.isServerAvailable()) { |
| 179 | logError( |
| 180 | "Stable Diffusion is still starting up, please wait. If this goes on beyond a few minutes, Stable Diffusion has probably crashed. Please check the error message in the command-line window.", |
| 181 | event, |
| 182 | outputMsg |
| 183 | ) |
| 184 | } else if (typeof event?.response === "object") { |
| 185 | let msg = "Stable Diffusion had an error reading the response:<br/><pre>" |
| 186 | if (this.exception) { |
| 187 | msg += `Error: ${this.exception.message}<br/>` |
| 188 | } |
| 189 | try { |
| 190 | // 'Response': body stream already read |
| 191 | msg += "Read: " + (await event.response.text()) |
| 192 | } catch (e) { |
| 193 | msg += "Unexpected end of stream. " |
| 194 | } |
| 195 | const bufferString = event.reader.bufferedString |
| 196 | if (bufferString) { |
| 197 | msg += "Buffered data: " + bufferString |
| 198 | } |
| 199 | msg += "</pre>" |
| 200 | logError(msg, event, outputMsg) |
| 201 | } |
| 202 | break |
| 203 | } |
| 204 | } |
| 205 | if ("update" in event) { |
| 206 | const stepUpdate = event.update |
no test coverage detected