mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-10-15 03:01:57 +00:00
Move jobs namespace back to http routes
This commit is contained in:
22
app/static/js/app/client.js
Normal file
22
app/static/js/app/client.js
Normal file
@@ -0,0 +1,22 @@
|
||||
nopaque.app.Client = class Client {
|
||||
constructor() {
|
||||
this.socket = io({transports: ['websocket'], upgrade: false});
|
||||
|
||||
// Endpoints
|
||||
this.corpora = new nopaque.app.endpoints.Corpora(this);
|
||||
this.jobs = new nopaque.app.endpoints.Jobs(this);
|
||||
this.users = new nopaque.app.endpoints.Users(this);
|
||||
|
||||
// Extensions
|
||||
this.toaster = new nopaque.app.extensions.Toaster(this);
|
||||
this.ui = new nopaque.app.extensions.UI(this);
|
||||
this.userHub = new nopaque.app.extensions.UserHub(this);
|
||||
}
|
||||
|
||||
init() {
|
||||
// Initialize extensions
|
||||
this.toaster.init();
|
||||
this.ui.init();
|
||||
this.userHub.init();
|
||||
}
|
||||
};
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user