mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: ctx.setInterval support
This commit is contained in:
1 parent
6e04a1a8a1
commit
672c553f4c
3 files changed
+12
-9
No files matched your search
@@ -31,9 +31,9 @@ export class Runtime {
|
|||||||
if (this.loaded) throw new Error(`Module ${this.filename} was already loaded`);
|
if (this.loaded) throw new Error(`Module ${this.filename} was already loaded`);
|
||||||
this.sideEffect = false;
|
this.sideEffect = false;
|
||||||
if (typeof module.dispose === 'function') this.disposables.push(module.dispose);
|
if (typeof module.dispose === 'function') this.disposables.push(module.dispose);
|
||||||
const T = (origFunc) => (origFunc ? (...args) => {
|
const T = (origFunc, disposeFunc?) => (origFunc ? (...args) => {
|
||||||
const res = origFunc(...args);
|
const res = origFunc(...args);
|
||||||
this.disposables.push(res);
|
this.disposables.push(disposeFunc ? () => disposeFunc(res) : res);
|
||||||
return res;
|
return res;
|
||||||
} : null);
|
} : null);
|
||||||
module.apply({
|
module.apply({
|
||||||
@@ -43,6 +43,9 @@ export class Runtime {
|
|||||||
once: T(bus.once),
|
once: T(bus.once),
|
||||||
off: bus.off,
|
off: bus.off,
|
||||||
addScript: T(addScript),
|
addScript: T(addScript),
|
||||||
|
setInterval: T(setInterval, clearInterval),
|
||||||
|
setTimeout: T(setTimeout, clearTimeout),
|
||||||
|
setImmediate: T(setImmediate, clearImmediate),
|
||||||
} as Context);
|
} as Context);
|
||||||
if (module.sideEffect) this.sideEffect = true;
|
if (module.sideEffect) this.sideEffect = true;
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { AggregatorRegistry, metric } from 'prom-client';
|
import { AggregatorRegistry, metric } from 'prom-client';
|
||||||
import * as system from 'hydrooj/src/model/system';
|
import * as system from 'hydrooj/src/model/system';
|
||||||
import * as bus from 'hydrooj/src/service/bus';
|
import * as bus from 'hydrooj/src/service/bus';
|
||||||
import { Handler, Route } from 'hydrooj/src/service/server';
|
import { Handler } from 'hydrooj/src/service/server';
|
||||||
import { registry } from './metrics';
|
import { registry } from './metrics';
|
||||||
|
|
||||||
declare module 'hydrooj/src/service/bus' {
|
declare module 'hydrooj/src/service/bus' {
|
||||||
@@ -42,11 +42,10 @@ class MetricsHandler extends Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bus.on('metrics', (id, metrics) => { instances[id] = metrics; });
|
export function apply(ctx) {
|
||||||
setInterval(async () => {
|
ctx.on('metrics', (id, metrics) => { instances[id] = metrics; });
|
||||||
|
ctx.setInterval(async () => {
|
||||||
bus.broadcast('metrics', process.env.NODE_APP_INSTANCE!, await registry.getMetricsAsJSON());
|
bus.broadcast('metrics', process.env.NODE_APP_INSTANCE!, await registry.getMetricsAsJSON());
|
||||||
}, 5000 * (+system.get('prom-client.collect_rate') || 1));
|
}, 5000 * (+system.get('prom-client.collect_rate') || 1));
|
||||||
|
ctx.Route('metrics', '/metrics', MetricsHandler);
|
||||||
global.Hydro.handler.prom = () => {
|
}
|
||||||
Route('metrics', '/metrics', MetricsHandler);
|
|
||||||
};
|
|
||||||
@@ -162,4 +162,5 @@ const dataPreviewPage = new AutoloadPage('dataPreview', () => {
|
|||||||
$(document).on('click', '[data-preview]', previewFile);
|
$(document).on('click', '[data-preview]', previewFile);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.Hydro.components.preview = { startEdit, previewFile };
|
||||||
export default dataPreviewPage;
|
export default dataPreviewPage;
|
||||||
Reference in new issue
Block a user