|
|
|
@ -13,62 +13,23 @@ import FactCheckOutlined from "@mui/icons-material/FactCheckOutlined" |
|
|
|
|
import {IconButton, LinearProgress, TableContainer, Table, TableBody, TableCell, TableHead, TableRow, TablePagination} from "@mui/material" |
|
|
|
|
import ConfirmDialog from "../confirm-dialog"; |
|
|
|
|
import smClient from "../../../api/sm/sm-client"; |
|
|
|
|
import {ProcessesResponseInterface, Status} from "../../../api/sm/responses/processes"; |
|
|
|
|
|
|
|
|
|
export interface ProcessExceptionInterface { |
|
|
|
|
message: string, |
|
|
|
|
file: string, |
|
|
|
|
line: number, |
|
|
|
|
code: number, |
|
|
|
|
trace: any[], |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export interface ProcessProgressInterface { |
|
|
|
|
total: number, |
|
|
|
|
progress: number, |
|
|
|
|
memory: any[], |
|
|
|
|
remaining: string |
|
|
|
|
percent: number |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export interface ProcessInterface { |
|
|
|
|
id: string, |
|
|
|
|
lock: string | null, |
|
|
|
|
containerUuid: string | null, |
|
|
|
|
pid: bigint | null, |
|
|
|
|
name: string, |
|
|
|
|
options: Record<string, any>, |
|
|
|
|
arguments: Record<string, any>, |
|
|
|
|
exception: ProcessExceptionInterface | null, |
|
|
|
|
progress: ProcessProgressInterface | null, |
|
|
|
|
outputId: string | null, |
|
|
|
|
createdAt: string, |
|
|
|
|
updatedAt: string | null, |
|
|
|
|
startedAt: string | null, |
|
|
|
|
pausedAt: string | null, |
|
|
|
|
cancelledAt: string | null |
|
|
|
|
completedAt: string | null |
|
|
|
|
status: Status |
|
|
|
|
canPlay: boolean |
|
|
|
|
canPause: boolean |
|
|
|
|
canRepeat: boolean |
|
|
|
|
canStop: boolean |
|
|
|
|
canKill: boolean |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
enum Status { |
|
|
|
|
Wait = 'wait', |
|
|
|
|
Running = 'running', |
|
|
|
|
Cancelled = 'cancelled', |
|
|
|
|
Error = 'error', |
|
|
|
|
Success = 'success', |
|
|
|
|
enum Action { |
|
|
|
|
Repeat, |
|
|
|
|
Stop, |
|
|
|
|
Kill, |
|
|
|
|
Play, |
|
|
|
|
Pause, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default function Processes() { |
|
|
|
|
const [processes, setProcesses] = useState<ProcessInterface[]>([]); |
|
|
|
|
const [processes, setProcesses] = useState<ProcessesResponseInterface[]>([]); |
|
|
|
|
const [page, setPage] = useState<number>(0); |
|
|
|
|
const [count, setCount] = useState<number>(0); |
|
|
|
|
const [open, setOpen] = useState<boolean>(false); |
|
|
|
|
const [selectedProcess, setSelectedProcess] = useState<ProcessInterface | null>(null); |
|
|
|
|
const [action, setAction] = useState<Action | null>(null); |
|
|
|
|
const [selectedProcess, setSelectedProcess] = useState<ProcessesResponseInterface | null>(null); |
|
|
|
|
|
|
|
|
|
let refreshLock = false |
|
|
|
|
let refreshProcesses = async () => { |
|
|
|
@ -84,7 +45,7 @@ export default function Processes() { |
|
|
|
|
setCount(Number(headers.get('X-Pagination-Count'))) |
|
|
|
|
refreshLock = false |
|
|
|
|
} |
|
|
|
|
let output = async (process: ProcessInterface) => { |
|
|
|
|
let output = async (process: ProcessesResponseInterface) => { |
|
|
|
|
const { data: output } = await smClient.getProcessOutput({ |
|
|
|
|
id: process.id |
|
|
|
|
}) |
|
|
|
@ -101,19 +62,20 @@ export default function Processes() { |
|
|
|
|
return () => clearInterval(timer); |
|
|
|
|
}, [page]); |
|
|
|
|
|
|
|
|
|
let isFinished = (process: ProcessInterface) => process.cancelledAt || process.completedAt |
|
|
|
|
let isFinished = (process: ProcessesResponseInterface) => process.cancelledAt || process.completedAt |
|
|
|
|
|
|
|
|
|
const handleChangePage = (event: any, page: number) => { |
|
|
|
|
setPage(page); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const openRepeatDialog = (process: ProcessInterface) => { |
|
|
|
|
const openDialog = (process: ProcessesResponseInterface, action: Action) => { |
|
|
|
|
setSelectedProcess(process) |
|
|
|
|
setOpen(true) |
|
|
|
|
setAction(action) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let lock = false |
|
|
|
|
const repeat = async (dialogId: string) => { |
|
|
|
|
const agreeCallback = async (dialogId: string) => { |
|
|
|
|
if (lock) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
@ -122,14 +84,33 @@ export default function Processes() { |
|
|
|
|
} |
|
|
|
|
lock = true |
|
|
|
|
|
|
|
|
|
await smClient.repeatProcess({ |
|
|
|
|
id: selectedProcess.id, |
|
|
|
|
requestId: dialogId |
|
|
|
|
}) |
|
|
|
|
if (action === Action.Repeat) { |
|
|
|
|
await smClient.repeatProcess({ |
|
|
|
|
id: selectedProcess.id, |
|
|
|
|
requestId: dialogId |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (action === Action.Stop) { |
|
|
|
|
await smClient.stopProcess(selectedProcess.id) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (action === Action.Kill) { |
|
|
|
|
await smClient.killProcess(selectedProcess.id) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (action === Action.Play) { |
|
|
|
|
await smClient.playProcess(selectedProcess.id) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (action === Action.Pause) { |
|
|
|
|
await smClient.pauseProcess(selectedProcess.id) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
lock = false |
|
|
|
|
setSelectedProcess(null) |
|
|
|
|
setOpen(false) |
|
|
|
|
setAction(null) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
@ -146,7 +127,7 @@ export default function Processes() { |
|
|
|
|
</TableRow> |
|
|
|
|
</TableHead> |
|
|
|
|
<TableBody> |
|
|
|
|
{processes.map((process: ProcessInterface, index: number) => ( |
|
|
|
|
{processes.map((process: ProcessesResponseInterface, index: number) => ( |
|
|
|
|
<TableRow key={process.id}> |
|
|
|
|
<TableCell>{process.name}</TableCell> |
|
|
|
|
<TableCell> |
|
|
|
@ -156,13 +137,13 @@ export default function Processes() { |
|
|
|
|
{process.progress && <span> |
|
|
|
|
{`${process.progress.progress}`} / {`${process.progress.total}`} - {process.progress.percent}% [{process.progress.memory}] / {process.progress.remaining} |
|
|
|
|
</span>} |
|
|
|
|
{process.canPlay && <IconButton title={`Play`} aria-label="Play"> |
|
|
|
|
{process.canPlay && <IconButton onClick={() => openDialog(process, Action.Play)} title={`Play`} aria-label="Play"> |
|
|
|
|
<PlayCircleOutline/> |
|
|
|
|
</IconButton>} |
|
|
|
|
{process.canPause && <IconButton title={`Pause`} aria-label="Pause"> |
|
|
|
|
{process.canPause && <IconButton onClick={() => openDialog(process, Action.Pause)} title={`Pause`} aria-label="Pause"> |
|
|
|
|
<PauseCircleOutline/> |
|
|
|
|
</IconButton>} |
|
|
|
|
{process.canStop && <IconButton title={`Stop`} aria-label="Stop"> |
|
|
|
|
{process.canStop && <IconButton onClick={() => openDialog(process, Action.Stop)} title={`Stop`} aria-label="Stop"> |
|
|
|
|
<StopCircleOutlined/> |
|
|
|
|
</IconButton>} |
|
|
|
|
</TableCell> |
|
|
|
@ -184,10 +165,10 @@ export default function Processes() { |
|
|
|
|
</IconButton>} |
|
|
|
|
</TableCell> |
|
|
|
|
<TableCell> |
|
|
|
|
{process.canRepeat && <IconButton onClick={() => openRepeatDialog(process)} title={`Repeat`} aria-label="Repeat"> |
|
|
|
|
{process.canRepeat && <IconButton onClick={() => openDialog(process, Action.Repeat)} title={`Repeat`} aria-label="Repeat"> |
|
|
|
|
<ReplayOutlined/> |
|
|
|
|
</IconButton>} |
|
|
|
|
{process.canKill && <IconButton title={`Kill`} aria-label="Kill"> |
|
|
|
|
{process.canKill && <IconButton onClick={() => openDialog(process, Action.Kill)} title={`Kill`} aria-label="Kill"> |
|
|
|
|
<DeleteForeverOutlined/> |
|
|
|
|
</IconButton>} |
|
|
|
|
{process?.outputId && <IconButton title={`Output`} onClick={() => output(process)} aria-label="Output"> |
|
|
|
@ -209,7 +190,7 @@ export default function Processes() { |
|
|
|
|
page={page} |
|
|
|
|
onPageChange={handleChangePage} |
|
|
|
|
/> |
|
|
|
|
<ConfirmDialog open={open} text={'!!!'} agreeCallback={repeat} closeCallback={() => { |
|
|
|
|
<ConfirmDialog open={open} text={'!!!'} agreeCallback={agreeCallback} closeCallback={() => { |
|
|
|
|
setSelectedProcess(null) |
|
|
|
|
setOpen(false) |
|
|
|
|
}}/> |
|
|
|
|