Добавил остальные действия

jwt
Sipachev Igor 2 years ago
parent 13e375f5d4
commit 7a84ff4a74
  1. 32
      api/sm/responses/processes.ts
  2. 4
      api/sm/responses/response.ts
  3. 10
      api/sm/schemas/kill-process.ts
  4. 10
      api/sm/schemas/pause-process.ts
  5. 10
      api/sm/schemas/play-process.ts
  6. 10
      api/sm/schemas/stop-process.ts
  7. 44
      api/sm/sm-client.ts
  8. 109
      components/elements/processes/index.tsx

@ -1,15 +1,17 @@
export interface ProcessExceptionInterface { export interface ProcessExceptionInterface {
message: string, message: string
file: string, file: string
line: number, line: number
code: number, code: number
trace: any[], trace: any[]
} }
export interface ProcessProgressInterface { export interface ProcessProgressInterface {
total: number, total: number
progress: number, progress: number
memory: any[], memory: string
remaining: string
percent: number
} }
export interface ProcessesResponseInterface { export interface ProcessesResponseInterface {
@ -29,4 +31,18 @@ export interface ProcessesResponseInterface {
pausedAt: string | null pausedAt: string | null
cancelledAt: string | null cancelledAt: string | null
completedAt: string | null completedAt: string | null
status: Status
canPlay: boolean
canPause: boolean
canRepeat: boolean
canStop: boolean
canKill: boolean
}
export enum Status {
Wait = 'wait',
Running = 'running',
Cancelled = 'cancelled',
Error = 'error',
Success = 'success',
} }

@ -1,4 +1,4 @@
export interface ResponseInterface { export interface ResponseInterface<T=any> {
data: any data: T
headers: Headers headers: Headers
} }

@ -0,0 +1,10 @@
import {Method, SchemaInterface} from "../../schema-client";
class KillProcessSchema implements SchemaInterface {
method = Method.POST
url = '/system-monitoring/processes/{id}/kill'
contentType = null;
}
export let killProcessSchema = new KillProcessSchema()
export default killProcessSchema

@ -0,0 +1,10 @@
import {Method, SchemaInterface} from "../../schema-client";
class PauseProcessSchema implements SchemaInterface {
method = Method.POST
url = '/system-monitoring/processes/{id}/pause'
contentType = null;
}
export let pauseProcessSchema = new PauseProcessSchema()
export default pauseProcessSchema

@ -0,0 +1,10 @@
import {Method, SchemaInterface} from "../../schema-client";
class PlayProcessSchema implements SchemaInterface {
method = Method.POST
url = '/system-monitoring/processes/{id}/play'
contentType = null;
}
export let playProcessSchema = new PlayProcessSchema()
export default playProcessSchema

@ -0,0 +1,10 @@
import {Method, SchemaInterface} from "../../schema-client";
class StopProcessSchema implements SchemaInterface {
method = Method.POST
url = '/system-monitoring/processes/{id}/stop'
contentType = null;
}
export let stopProcessSchema = new StopProcessSchema()
export default stopProcessSchema

@ -11,6 +11,10 @@ import {RepeatProcessRequest} from "./requests/repeat-process";
import repeatProcessSchema from "./schemas/repeat-process"; import repeatProcessSchema from "./schemas/repeat-process";
import processOutputSchema from "./schemas/process-output"; import processOutputSchema from "./schemas/process-output";
import {ProcessOutputRequest} from "./requests/process-ouput"; import {ProcessOutputRequest} from "./requests/process-ouput";
import playProcessSchema from "./schemas/play-process";
import pauseProcessSchema from "./schemas/pause-process";
import stopProcessSchema from "./schemas/stop-process";
import killProcessSchema from "./schemas/kill-process";
export class SMClient { export class SMClient {
schemaClient: SchemaClient schemaClient: SchemaClient
@ -21,10 +25,10 @@ export class SMClient {
}) })
} }
async getCommands(): Promise<ResponseInterface> { async getCommands(): Promise<ResponseInterface<CommandResponseInterface[]>> {
let { responseData, headers } = await this.schemaClient.send(commandsSchema, {}) let { responseData, headers } = await this.schemaClient.send(commandsSchema, {})
return { return {
data: responseData as CommandResponseInterface[], data: responseData,
headers: headers headers: headers
} }
} }
@ -37,10 +41,10 @@ export class SMClient {
} }
} }
async getProcesses(data: GetProcessesRequest | PaginationRequest): Promise<ResponseInterface> { async getProcesses(data: GetProcessesRequest | PaginationRequest): Promise<ResponseInterface<ProcessesResponseInterface[]>> {
let { responseData, headers } = await this.schemaClient.send(processesSchema, data) let { responseData, headers } = await this.schemaClient.send(processesSchema, data)
return { return {
data: responseData as ProcessesResponseInterface[], data: responseData,
headers: headers headers: headers
} }
} }
@ -60,6 +64,38 @@ export class SMClient {
headers: headers headers: headers
} }
} }
async playProcess(id: string): Promise<ResponseInterface> {
let { headers } = await this.schemaClient.send(playProcessSchema, {id})
return {
data: null,
headers: headers
}
}
async pauseProcess(id: string): Promise<ResponseInterface> {
let { headers } = await this.schemaClient.send(pauseProcessSchema, {id})
return {
data: null,
headers: headers
}
}
async stopProcess(id: string): Promise<ResponseInterface> {
let { headers } = await this.schemaClient.send(stopProcessSchema, {id})
return {
data: null,
headers: headers
}
}
async killProcess(id: string): Promise<ResponseInterface> {
let { headers } = await this.schemaClient.send(killProcessSchema, {id})
return {
data: null,
headers: headers
}
}
} }
export let smClient = new SMClient export let smClient = new SMClient

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

Loading…
Cancel
Save