requireSth有可能为空
This commit is contained in:
parent
dbcdec7315
commit
755240acc4
|
|
@ -220,13 +220,15 @@ class AppLoader extends types_1.AppLoader {
|
|||
}
|
||||
}]);
|
||||
};
|
||||
for (const router in endpoints) {
|
||||
const item = endpoints[router];
|
||||
if (item instanceof Array) {
|
||||
item.forEach(ele => transformEndpointItem(router, ele));
|
||||
}
|
||||
else {
|
||||
transformEndpointItem(router, item);
|
||||
if (endpoints) {
|
||||
for (const router in endpoints) {
|
||||
const item = endpoints[router];
|
||||
if (item instanceof Array) {
|
||||
item.forEach(ele => transformEndpointItem(router, ele));
|
||||
}
|
||||
else {
|
||||
transformEndpointItem(router, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.synchronizer) {
|
||||
|
|
@ -285,7 +287,7 @@ class AppLoader extends types_1.AppLoader {
|
|||
const watchers = this.requireSth('lib/watchers/index');
|
||||
const { ActionDefDict } = require(`${this.path}/lib/oak-app-domain/ActionDefDict`);
|
||||
const { watchers: adWatchers } = (0, IntrinsicLogics_1.makeIntrinsicLogics)(this.dbStore.getSchema(), ActionDefDict);
|
||||
const totalWatchers = watchers.concat(adWatchers);
|
||||
const totalWatchers = (watchers || []).concat(adWatchers);
|
||||
let count = 0;
|
||||
const execOne = async (watcher, start) => {
|
||||
try {
|
||||
|
|
@ -317,38 +319,40 @@ class AppLoader extends types_1.AppLoader {
|
|||
}
|
||||
startTimers() {
|
||||
const timers = this.requireSth('lib/timers/index');
|
||||
for (const timer of timers) {
|
||||
const { cron, name } = timer;
|
||||
(0, node_schedule_1.scheduleJob)(name, cron, async (date) => {
|
||||
const start = Date.now();
|
||||
console.log(`定时器【${name}】开始执行,时间是【${date.toLocaleTimeString()}】`);
|
||||
if (timer.hasOwnProperty('entity')) {
|
||||
try {
|
||||
const result = await this.execWatcher(timer);
|
||||
console.log(`定时器【${name}】执行成功,耗时${Date.now() - start}毫秒】,结果是`, result);
|
||||
if (timers) {
|
||||
for (const timer of timers) {
|
||||
const { cron, name } = timer;
|
||||
(0, node_schedule_1.scheduleJob)(name, cron, async (date) => {
|
||||
const start = Date.now();
|
||||
console.log(`定时器【${name}】开始执行,时间是【${date.toLocaleTimeString()}】`);
|
||||
if (timer.hasOwnProperty('entity')) {
|
||||
try {
|
||||
const result = await this.execWatcher(timer);
|
||||
console.log(`定时器【${name}】执行成功,耗时${Date.now() - start}毫秒】,结果是`, result);
|
||||
}
|
||||
catch (err) {
|
||||
console.log(`定时器【${name}】执行成功,耗时${Date.now() - start}毫秒】,错误是`, err);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.log(`定时器【${name}】执行成功,耗时${Date.now() - start}毫秒】,错误是`, err);
|
||||
else {
|
||||
const context = await this.makeContext();
|
||||
try {
|
||||
const { timer: timerFn } = timer;
|
||||
const result = await timerFn(context);
|
||||
console.log(`定时器【${name}】执行成功,耗时${Date.now() - start}毫秒,结果是【${result}】`);
|
||||
await context.commit();
|
||||
}
|
||||
catch (err) {
|
||||
console.warn(`定时器【${name}】执行失败,耗时${Date.now() - start}毫秒,错误是`, err);
|
||||
await context.rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const context = await this.makeContext();
|
||||
try {
|
||||
const { timer: timerFn } = timer;
|
||||
const result = await timerFn(context);
|
||||
console.log(`定时器【${name}】执行成功,耗时${Date.now() - start}毫秒,结果是【${result}】`);
|
||||
await context.commit();
|
||||
}
|
||||
catch (err) {
|
||||
console.warn(`定时器【${name}】执行失败,耗时${Date.now() - start}毫秒,错误是`, err);
|
||||
await context.rollback();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
async execStartRoutines() {
|
||||
const routines = this.requireSth('lib/routines/start');
|
||||
const routines = this.requireSth('lib/routines/start') || [];
|
||||
if (this.synchronizer) {
|
||||
const routine = this.synchronizer.getSyncRoutine();
|
||||
routines.push(routine);
|
||||
|
|
|
|||
|
|
@ -84,8 +84,8 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Backe
|
|||
const { storageSchema } = require(`${path}/lib/oak-app-domain/Storage`);
|
||||
const depGraph = analyzeDepedency(process.cwd());
|
||||
this.externalDependencies = Object.keys(depGraph.ascOrder);
|
||||
const { authDeduceRelationMap, selectFreeEntities, updateFreeDict } = this.requireSth('lib/configuration/relation');
|
||||
this.aspectDict = Object.assign({}, generalAspectDict, this.requireSth('lib/aspects/index'));
|
||||
const { authDeduceRelationMap, selectFreeEntities, updateFreeDict } = this.requireSth('lib/configuration/relation')!;
|
||||
this.aspectDict = Object.assign({}, generalAspectDict, this.requireSth('lib/aspects/index')!);
|
||||
this.dbStore = new DbStore<ED, Cxt>(storageSchema, () => this.contextBuilder(this.dbStore), dbConfig, authDeduceRelationMap, selectFreeEntities, updateFreeDict);
|
||||
if (ns) {
|
||||
this.dataSubscriber = new DataSubscriber(ns, nsServer);
|
||||
|
|
@ -126,8 +126,8 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Backe
|
|||
}
|
||||
|
||||
initTriggers() {
|
||||
const triggers = this.requireSth('lib/triggers/index');
|
||||
const checkers = this.requireSth('lib/checkers/index');
|
||||
const triggers = this.requireSth('lib/triggers/index')!;
|
||||
const checkers = this.requireSth('lib/checkers/index')!;
|
||||
const { actionDefDict } = require(`${this.path}/lib/oak-app-domain/ActionDefDict`);
|
||||
|
||||
const { triggers: adTriggers, checkers: adCheckers } = makeIntrinsicLogics(this.dbStore.getSchema(), actionDefDict);
|
||||
|
|
@ -211,7 +211,7 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Backe
|
|||
async initialize(truncate?: boolean) {
|
||||
await this.dbStore.initialize({ ifExists: 'dropIfNotStatic' });
|
||||
|
||||
const data = this.requireSth('lib/data/index');
|
||||
const data = this.requireSth('lib/data/index')!;
|
||||
const context = this.contextBuilder(this.dbStore);
|
||||
for (const entity in data) {
|
||||
let rows = data[entity];
|
||||
|
|
@ -283,15 +283,17 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Backe
|
|||
}]
|
||||
);
|
||||
};
|
||||
for (const router in endpoints) {
|
||||
const item = endpoints[router];
|
||||
if (item instanceof Array) {
|
||||
item.forEach(
|
||||
ele => transformEndpointItem(router, ele)
|
||||
);
|
||||
}
|
||||
else {
|
||||
transformEndpointItem(router, item);
|
||||
if (endpoints) {
|
||||
for (const router in endpoints) {
|
||||
const item = endpoints[router];
|
||||
if (item instanceof Array) {
|
||||
item.forEach(
|
||||
ele => transformEndpointItem(router, ele)
|
||||
);
|
||||
}
|
||||
else {
|
||||
transformEndpointItem(router, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -357,7 +359,7 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Backe
|
|||
const { ActionDefDict } = require(`${this.path}/lib/oak-app-domain/ActionDefDict`);
|
||||
|
||||
const { watchers: adWatchers } = makeIntrinsicLogics(this.dbStore.getSchema(), ActionDefDict);
|
||||
const totalWatchers = (<Watcher<ED, keyof ED, Cxt>[]>watchers).concat(adWatchers);
|
||||
const totalWatchers = (<Watcher<ED, keyof ED, Cxt>[]>watchers || []).concat(adWatchers);
|
||||
|
||||
let count = 0;
|
||||
const execOne = async (watcher: Watcher<ED, keyof ED, Cxt>, start: number) => {
|
||||
|
|
@ -393,40 +395,42 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Backe
|
|||
|
||||
startTimers() {
|
||||
const timers: Timer<ED, keyof ED, Cxt>[] = this.requireSth('lib/timers/index');
|
||||
for (const timer of timers) {
|
||||
const { cron, name } = timer;
|
||||
scheduleJob(name, cron, async (date) => {
|
||||
const start = Date.now();
|
||||
console.log(`定时器【${name}】开始执行,时间是【${date.toLocaleTimeString()}】`);
|
||||
|
||||
if (timer.hasOwnProperty('entity')) {
|
||||
try {
|
||||
const result = await this.execWatcher(timer as Watcher<ED, keyof ED, Cxt>);
|
||||
console.log(`定时器【${name}】执行成功,耗时${Date.now() - start}毫秒】,结果是`, result);
|
||||
if (timers) {
|
||||
for (const timer of timers) {
|
||||
const { cron, name } = timer;
|
||||
scheduleJob(name, cron, async (date) => {
|
||||
const start = Date.now();
|
||||
console.log(`定时器【${name}】开始执行,时间是【${date.toLocaleTimeString()}】`);
|
||||
|
||||
if (timer.hasOwnProperty('entity')) {
|
||||
try {
|
||||
const result = await this.execWatcher(timer as Watcher<ED, keyof ED, Cxt>);
|
||||
console.log(`定时器【${name}】执行成功,耗时${Date.now() - start}毫秒】,结果是`, result);
|
||||
}
|
||||
catch (err) {
|
||||
console.log(`定时器【${name}】执行成功,耗时${Date.now() - start}毫秒】,错误是`, err);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.log(`定时器【${name}】执行成功,耗时${Date.now() - start}毫秒】,错误是`, err);
|
||||
else {
|
||||
const context = await this.makeContext();
|
||||
try {
|
||||
const { timer: timerFn } = timer as FreeTimer<ED, Cxt>;
|
||||
const result = await timerFn(context);
|
||||
console.log(`定时器【${name}】执行成功,耗时${Date.now() - start}毫秒,结果是【${result}】`);
|
||||
await context.commit();
|
||||
}
|
||||
catch (err) {
|
||||
console.warn(`定时器【${name}】执行失败,耗时${Date.now() - start}毫秒,错误是`, err);
|
||||
await context.rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const context = await this.makeContext();
|
||||
try {
|
||||
const { timer: timerFn } = timer as FreeTimer<ED, Cxt>;
|
||||
const result = await timerFn(context);
|
||||
console.log(`定时器【${name}】执行成功,耗时${Date.now() - start}毫秒,结果是【${result}】`);
|
||||
await context.commit();
|
||||
}
|
||||
catch (err) {
|
||||
console.warn(`定时器【${name}】执行失败,耗时${Date.now() - start}毫秒,错误是`, err);
|
||||
await context.rollback();
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async execStartRoutines() {
|
||||
const routines: Routine<ED, keyof ED, Cxt>[] = this.requireSth('lib/routines/start');
|
||||
const routines: Routine<ED, keyof ED, Cxt>[] = this.requireSth('lib/routines/start') || [];
|
||||
if (this.synchronizer) {
|
||||
const routine = this.synchronizer.getSyncRoutine();
|
||||
routines.push(routine);
|
||||
|
|
|
|||
Loading…
Reference in New Issue