Replace eris-fleet with a pm2-based cluster system, overhaul image handling, removed azure image api
This commit is contained in:
parent
5a3364736d
commit
db0decf71a
45 changed files with 1777 additions and 857 deletions
|
@ -6,6 +6,9 @@ The esmBot image API is a combined HTTP and WebSocket API. The default port to a
|
|||
### GET `/image/?id=<job id>`
|
||||
Get image data after job is finished running. The Content-Type header is properly set.
|
||||
|
||||
### GET `/count`
|
||||
Get the current amount of running jobs. Response is a plaintext number value.
|
||||
|
||||
## WebSockets
|
||||
A client sends *requests* (T-messages) to a server, which subsequently *replies* (R-messages) to the client.
|
||||
### Message IDs
|
||||
|
@ -24,11 +27,11 @@ A client sends *requests* (T-messages) to a server, which subsequently *replies*
|
|||
[j] means JSON data that goes until the end of the message.
|
||||
`tag` is used to identify a request/response pair, like `lock` in the original API. `jid` is used to identify a job. `job` is a job object.
|
||||
- Rerror tag[2] error[s]
|
||||
- Tqueue tag[2] jid[4] job[j]
|
||||
- Tqueue tag[2] jid[8] job[j]
|
||||
- Rqueue tag[2]
|
||||
- Tcancel tag[2] jid[4]
|
||||
- Tcancel tag[2] jid[8]
|
||||
- Rcancel tag[2]
|
||||
- Twait tag[2] jid[4]
|
||||
- Twait tag[2] jid[8]
|
||||
- Rwait tag[2]
|
||||
- Rinit tag[2] max_jobs[2] running_jobs[2] formats[j]
|
||||
|
||||
|
@ -42,6 +45,7 @@ The job object is formatted like this:
|
|||
"params": { // content varies depending on the command, some common parameters are listed here
|
||||
"type": string, // mime type of output, should usually be the same as input
|
||||
...
|
||||
}
|
||||
},
|
||||
"name": string // filename of the image, without extension
|
||||
}
|
||||
```
|
||||
|
|
13
api/index.js
13
api/index.js
|
@ -107,8 +107,8 @@ wss.on("connection", (ws, request) => {
|
|||
const tag = msg.slice(1, 3);
|
||||
const req = msg.toString().slice(3);
|
||||
if (opcode == Tqueue) {
|
||||
const id = msg.readUInt32LE(3);
|
||||
const obj = msg.slice(7);
|
||||
const id = msg.readBigInt64LE(3);
|
||||
const obj = msg.slice(11);
|
||||
const job = { msg: obj, num: jobAmount, verifyEvent: new EventEmitter() };
|
||||
jobs.set(id, job);
|
||||
queue.push(id);
|
||||
|
@ -128,7 +128,7 @@ wss.on("connection", (ws, request) => {
|
|||
const cancelResponse = Buffer.concat([Buffer.from([Rcancel]), tag]);
|
||||
ws.send(cancelResponse);
|
||||
} else if (opcode == Twait) {
|
||||
const id = msg.readUInt32LE(3);
|
||||
const id = msg.readBigUInt64LE(3);
|
||||
const job = jobs.get(id);
|
||||
if (!job) {
|
||||
const errorResponse = Buffer.concat([Buffer.from([Rerror]), tag, Buffer.from("Invalid job ID")]);
|
||||
|
@ -178,7 +178,7 @@ httpServer.on("request", async (req, res) => {
|
|||
res.statusCode = 400;
|
||||
return res.end("400 Bad Request");
|
||||
}
|
||||
const id = parseInt(reqUrl.searchParams.get("id"));
|
||||
const id = BigInt(reqUrl.searchParams.get("id"));
|
||||
if (!jobs.has(id)) {
|
||||
res.statusCode = 410;
|
||||
return res.end("410 Gone");
|
||||
|
@ -208,6 +208,11 @@ httpServer.on("request", async (req, res) => {
|
|||
return res.end(data, (err) => {
|
||||
if (err) error(err);
|
||||
});
|
||||
} else if (reqUrl.pathname === "/count" && req.method === "GET") {
|
||||
log(`Sending job count to ${req.socket.remoteAddress}:${req.socket.remotePort} via HTTP`);
|
||||
return res.end(jobAmount.toString(), (err) => {
|
||||
if (err) error(err);
|
||||
});
|
||||
} else {
|
||||
res.statusCode = 404;
|
||||
return res.end("404 Not Found");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue