import Button from '@material-ui/core/Button'; import Snackbar from '@material-ui/core/Snackbar'; import TableCell from '@material-ui/core/TableCell'; import TableRow from '@material-ui/core/TableRow'; import * as React from 'react'; import { IGlobalWindow, IWorkerProps } from "./interfaces"; declare var window: IGlobalWindow; class Worker extends React.Component { constructor(props: IWorkerProps) { super(props) this.handleQuietClick = this.handleQuietClick.bind(this) this.handleStopClick = this.handleStopClick.bind(this) this.handleNotificationClose = this.handleNotificationClose.bind(this) this.state = { notificationMessage: , notificationOpen: false, } } public render() { const worker = this.props.worker; return ( {worker.worker_id} {worker.max_thread_size} {worker.current_queue_size} {worker.current_executing_size} {worker.executor_status} {worker.polling_model_names} {worker.last_heartbeated_at} ) } private handleQuietClick(event: any) { const worker = this.props.worker; fetch(`${window.mountPath}/signals`, { body: JSON.stringify({"worker_id": worker.worker_id, "signal": "TSTP"}), headers: {"content-type": "application/json"}, method: "POST" }).then(this.handleResponseStatus).then((res) => { this.setState({ notificationMessage: Quiet {worker.worker_id}, notificationOpen: true, }) }).catch((err) => { this.setState({ notificationMessage: Failed to Quiet ({err.message}), notificationOpen: true, }) }) } private handleStopClick(event: any) { const worker = this.props.worker; fetch(`${window.mountPath}/signals`, { body: JSON.stringify({"worker_id": worker.worker_id, "signal": "TERM"}), headers: {"content-type": "application/json"}, method: "POST" }).then(this.handleResponseStatus).then((res) => { this.setState({ notificationMessage: Stop {worker.worker_id}, notificationOpen: true, }) }).catch((err) => { this.setState({ notificationMessage: Failed to Stop ({err.message}), notificationOpen: true, }) }) } private handleResponseStatus(res: Response): Promise { if (!res.ok) { return res.json().then((data: any) => { throw new Error(data.error); }) } else { return Promise.resolve(res); } } private handleNotificationClose(ev: any, reason: any) { this.setState({ ...this.state, notificationOpen: false, }) } } export default Worker;