(skipDocker = true, waitSeconds = 10)
| 318 | |
| 319 | // Soft exit: optional docker skip and configurable wait timeout |
| 320 | softExit(skipDocker = true, waitSeconds = 10) { |
| 321 | const promises: Promise<void>[] = []; |
| 322 | for (const iterator of this.instances) { |
| 323 | const instance = iterator[1]; |
| 324 | if (instance.status() !== Instance.STATUS_STOP) { |
| 325 | if (skipDocker && instance.config.processType === "docker") { |
| 326 | logger.info( |
| 327 | `Skipping Docker instance ${instance.config.nickname} (${instance.instanceUuid}) during soft shutdown...` |
| 328 | ); |
| 329 | continue; |
| 330 | } else { |
| 331 | // Soft close general instances (don't force kill) |
| 332 | promises.push(this.exitInstance(instance, false)); |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | Promise.all(promises); |
| 337 | |
| 338 | return new Promise<void>((resolve) => { |
| 339 | let checkCount = 0; |
| 340 | const checkTask = setInterval(() => { |
| 341 | let count = 0; |
| 342 | checkCount++; |
| 343 | for (const [_, instance] of this.instances) { |
| 344 | if (instance.status() !== Instance.STATUS_STOP) { |
| 345 | if (skipDocker && instance.config.processType === "docker") continue; |
| 346 | count++; |
| 347 | if (checkCount > waitSeconds) { |
| 348 | logger.info( |
| 349 | $t("TXT_CODE_eadac3c2", { |
| 350 | instance: instance.config.nickname |
| 351 | }) |
| 352 | ); |
| 353 | // If it takes too long, force close target instances |
| 354 | this.exitInstance(instance, true); |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | if (count === 0) { |
| 359 | logger.info($t("TXT_CODE_187bb567")); |
| 360 | clearInterval(checkTask); |
| 361 | resolve(); |
| 362 | } else { |
| 363 | logger.info($t("TXT_CODE_6f23ce93", { count })); |
| 364 | } |
| 365 | }, 1000); |
| 366 | }); |
| 367 | } |
| 368 | |
| 369 | getInstances() { |
| 370 | let newArr = new Array<Instance>(); |
no test coverage detected