Avoid multiple commands at the same for a stack

This commit is contained in:
Louis Lam 2023-11-26 17:29:53 +08:00
parent 16cdaa8ed5
commit 69e0f77830

View file

@ -5,8 +5,6 @@ import { LimitQueue } from "./utils/limit-queue";
import { DockgeSocket } from "./util-server"; import { DockgeSocket } from "./util-server";
import { import {
allowedCommandList, allowedRawKeys, allowedCommandList, allowedRawKeys,
getComposeTerminalName,
getCryptoRandomInt,
PROGRESS_TERMINAL_ROWS, PROGRESS_TERMINAL_ROWS,
TERMINAL_COLS, TERMINAL_COLS,
TERMINAL_ROWS TERMINAL_ROWS
@ -207,14 +205,20 @@ export class Terminal {
} }
public static exec(server : DockgeServer, socket : DockgeSocket | undefined, terminalName : string, file : string, args : string | string[], cwd : string) : Promise<number> { public static exec(server : DockgeServer, socket : DockgeSocket | undefined, terminalName : string, file : string, args : string | string[], cwd : string) : Promise<number> {
const terminal = new Terminal(server, terminalName, file, args, cwd); return new Promise((resolve, reject) => {
// check if terminal exists
if (Terminal.terminalMap.has(terminalName)) {
reject("Another operation is already running, please try again later.");
return;
}
let terminal = new Terminal(server, terminalName, file, args, cwd);
terminal.rows = PROGRESS_TERMINAL_ROWS; terminal.rows = PROGRESS_TERMINAL_ROWS;
if (socket) { if (socket) {
terminal.join(socket); terminal.join(socket);
} }
return new Promise((resolve) => {
terminal.onExit((exitCode : number) => { terminal.onExit((exitCode : number) => {
resolve(exitCode); resolve(exitCode);
}); });