forked from extern/podman-compose
example nodejs project
This commit is contained in:
31
examples/nodeproj/lib/commands/task.js
Normal file
31
examples/nodeproj/lib/commands/task.js
Normal file
@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
import {proj} from "../proj";
|
||||
|
||||
async function loop() {
|
||||
const poped = await proj.predis.blpop("queue", 5);
|
||||
const task_desc_s = poped[1];
|
||||
let task_desc;
|
||||
try {
|
||||
task_desc = JSON.parse(task_desc_s);
|
||||
} catch (e) {
|
||||
proj.logger.exception(e);
|
||||
}
|
||||
proj.logger.info("got task "+task_desc.func);
|
||||
const func = task_desc.func;
|
||||
const args = task_desc.args;
|
||||
if (typeof(proj.tasks[func])!="function") {
|
||||
console.log(`task ${func} not found`);
|
||||
process.exit(-1)
|
||||
}
|
||||
try {
|
||||
await ((this.tasks[func])(...args));
|
||||
} catch (e) {
|
||||
console.exception(e);
|
||||
}
|
||||
}
|
||||
|
||||
export async function start() {
|
||||
while(true) {
|
||||
loop();
|
||||
}
|
||||
}
|
22
examples/nodeproj/lib/commands/web.js
Normal file
22
examples/nodeproj/lib/commands/web.js
Normal file
@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
import {proj} from "../proj";
|
||||
|
||||
import http from "http";
|
||||
import express from "express";
|
||||
|
||||
|
||||
export async function start() {
|
||||
const app = express();
|
||||
app.use(proj.logger.express_logger);
|
||||
const server = http.createServer(app);
|
||||
|
||||
// Routing
|
||||
app.use(express.static(proj.config.basedir + "/public"));
|
||||
app.get("/healthz", function(req, res) {
|
||||
res.send("ok@"+Date.now());
|
||||
});
|
||||
|
||||
server.listen(proj.config.LISTEN_PORT, proj.config.LISTEN_HOST, function() {
|
||||
proj.logger.warn(`listening at port ${proj.config.LISTEN_PORT}`);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user