You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/hydro/entry/master.ts

71 lines
2.2 KiB
TypeScript

4 years ago
/* eslint-disable no-await-in-loop */
/* eslint-disable import/no-dynamic-require */
import {
lib, service, model, setting,
builtinLib, builtinHandler, builtinModel,
} from './common';
4 years ago
4 years ago
export async function load(call, args) {
let pending = args;
4 years ago
const fail = [];
require('../lib/i18n');
require('../utils');
require('../error');
try {
require('../options').default();
4 years ago
} catch (e) {
await call({ entry: 'setup', newProcess: true });
4 years ago
}
const bus = require('../service/bus');
4 years ago
await new Promise((resolve) => {
const h = () => {
console.log('Database connected');
bus.unsubscribe(['system_database_connected'], h);
resolve();
};
bus.subscribe(['system_database_connected'], h);
require('../service/db');
});
for (const i of builtinLib) require(`../lib/${i}`);
await lib(pending, fail);
require('../service/gridfs');
require('../service/monitor');
const server = require('../service/server');
await server.prepare();
4 years ago
await service(pending, fail);
for (const i of builtinModel) require(`../model/${i}`);
for (const i of builtinHandler) require(`../handler/${i}`);
await model(pending, fail);
for (const m in global.Hydro.model) {
if (global.Hydro.model[m].ensureIndexes) {
await global.Hydro.model[m].ensureIndexes();
}
}
const modelSystem = require('../model/system');
const modelSetting = require('../model/setting');
const dbVer = await modelSystem.get('db.ver');
4 years ago
if (dbVer !== 1) {
const ins = require('../script/install');
await ins.run({ username: 'Root', password: 'rootroot' });
}
await setting(pending, fail, modelSetting);
4 years ago
for (const i in global.Hydro.service) {
if (global.Hydro.service[i].postInit) {
try {
await global.Hydro.service[i].postInit();
} catch (e) {
console.error(e);
}
}
}
for (const postInit of global.Hydro.postInit) {
try {
await postInit();
} catch (e) {
console.error(e);
}
}
4 years ago
pending = [];
return await modelSystem.get('server.worker');
4 years ago
}