2024-12-06 11:41:36 +01:00

38 lines
852 B
JavaScript

nopaque.app.endpoints.Jobs = class Jobs {
constructor(app) {
this.app = app;
this.socket = io('/jobs', {transports: ['websocket'], upgrade: false});
}
async delete(id) {
const response = await this.socket.emitWithAck('delete', id);
if (response.status != 202) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
return response.body;
}
async log(id) {
const response = await this.socket.emitWithAck('log', id);
if (response.status != 200) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
return response.body;
}
async restart(id) {
const response = await this.socket.emitWithAck('restart', id);
if (response.status != 202) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
return response.body;
}
}