Move jobs namespace back to http routes

This commit is contained in:
Patrick Jentsch
2024-12-12 10:32:08 +01:00
parent 328f85ba52
commit bb60a2ba67
8 changed files with 157 additions and 164 deletions

View File

@ -1,4 +1,4 @@
nopaque.App = class App {
nopaque.app.Client = class Client {
constructor() {
this.socket = io({transports: ['websocket'], upgrade: false});

View File

@ -1,37 +1,47 @@
nopaque.app.endpoints.Jobs = class Jobs {
constructor(app) {
this.app = app;
async delete(jobId) {
const options = {
headers: {
Accept: 'application/json'
},
method: 'DELETE'
};
this.socket = io('/jobs', {transports: ['websocket'], upgrade: false});
const response = await fetch(`/jobs/${jobId}`, options);
const data = await response.json();
if (!response.ok) {throw new Error(`${data.name}: ${data.description}`);}
return data;
}
async delete(id) {
const response = await this.socket.emitWithAck('delete', id);
async log(jobId) {
const options = {
headers: {
Accept: 'application/json'
}
};
if (response.status != 202) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
const response = await fetch(`/jobs/${jobId}/log`, options);
const data = await response.json();
return response.body;
if (!response.ok) {throw new Error(`${data.name}: ${data.description}`);}
return data;
}
async log(id) {
const response = await this.socket.emitWithAck('log', id);
async restart(jobId) {
const options = {
headers: {
Accept: 'application/json'
}
};
if (response.status != 200) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
const response = await fetch(`/jobs/${jobId}/restart`, options);
const data = await response.json();
return response.body;
}
if (!response.ok) {throw new Error(`${data.name}: ${data.description}`);}
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;
return data;
}
}