mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
- Added a new service for executing synthetic monitor scripts. - Introduced API endpoint for running synthetic monitors. - Created configuration for synthetic monitor execution parameters. - Implemented execution logic with retry mechanisms and timeout handling. - Added support for multiple browser types and screen sizes. - Integrated logging and error handling for better observability. - Established child process management for executing scripts in isolation. - Updated docker-compose configuration to include the new service.
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import ClusterKeyAuthorization from "Common/Server/Middleware/ClusterKeyAuthorization";
|
|
import Express, {
|
|
ExpressRequest,
|
|
ExpressResponse,
|
|
ExpressRouter,
|
|
NextFunction,
|
|
} from "Common/Server/Utils/Express";
|
|
import Response from "Common/Server/Utils/Response";
|
|
import BadDataException from "Common/Types/Exception/BadDataException";
|
|
import logger from "Common/Server/Utils/Logger";
|
|
import { JSONArray } from "Common/Types/JSON";
|
|
import SyntheticMonitorProcessRunner from "../Execution/SyntheticMonitorProcessRunner";
|
|
import { SyntheticMonitorExecutionRequest } from "../Types/SyntheticMonitorExecution";
|
|
|
|
const router: ExpressRouter = Express.getRouter();
|
|
|
|
router.post(
|
|
"/run",
|
|
ClusterKeyAuthorization.isAuthorizedServiceMiddleware,
|
|
async (
|
|
req: ExpressRequest,
|
|
res: ExpressResponse,
|
|
next: NextFunction,
|
|
): Promise<void> => {
|
|
try {
|
|
const request: SyntheticMonitorExecutionRequest =
|
|
req.body as SyntheticMonitorExecutionRequest;
|
|
|
|
if (!request || typeof request.script !== "string") {
|
|
throw new BadDataException("Synthetic monitor script is required");
|
|
}
|
|
|
|
const response = await SyntheticMonitorProcessRunner.execute(request);
|
|
|
|
return Response.sendJsonObjectResponse(req, res, {
|
|
results: response.results as unknown as JSONArray,
|
|
});
|
|
} catch (error: unknown) {
|
|
logger.error(error);
|
|
return next(error);
|
|
}
|
|
},
|
|
);
|
|
|
|
export default router;
|