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

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. 101
      components/elements/processes/index.tsx

@ -1,15 +1,17 @@
export interface ProcessExceptionInterface {
message: string,
file: string,
line: number,
code: number,
trace: any[],
message: string
file: string
line: number
code: number
trace: any[]
}
export interface ProcessProgressInterface {
total: number,
progress: number,
memory: any[],
total: number
progress: number
memory: string
remaining: string
percent: number
}
export interface ProcessesResponseInterface {
@ -29,4 +31,18 @@ export interface ProcessesResponseInterface {
pausedAt: string | null
cancelledAt: 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 {
data: any
export interface ResponseInterface<T=any> {
data: T
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 processOutputSchema from "./schemas/process-output";
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 {
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, {})
return {
data: responseData as CommandResponseInterface[],
data: responseData,
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)
return {
data: responseData as ProcessesResponseInterface[],
data: responseData,
headers: headers
}
}
@ -60,6 +64,38 @@ export class SMClient {
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

@ -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
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)
}}/>

Loading…
Cancel
Save