mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: cordis alpha.7
This commit is contained in:
14 files changed
+40
-34
No files matched your search
@@ -55,10 +55,11 @@ export class MongoService extends Service {
|
||||
return mongourl;
|
||||
}
|
||||
|
||||
async [Service.setup]() {
|
||||
async *[Context.init]() {
|
||||
const mongourl = await MongoService.getUrl();
|
||||
const url = mongoUri.parse(mongourl);
|
||||
this.client = await MongoClient.connect(mongourl);
|
||||
yield () => { this.client.close(); }
|
||||
this.db = this.client.db(url.database || 'hydro');
|
||||
await bus.parallel('database/connect', this.db);
|
||||
this.ctx.setInterval(() => this.fixExpireAfter(), Time.hour);
|
||||
@@ -176,11 +177,6 @@ export class MongoService extends Service {
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public async apply(ctx) {
|
||||
await this.start();
|
||||
ctx.on('dispose', () => this.client.close());
|
||||
}
|
||||
}
|
||||
|
||||
/** @deprecated use ctx.db instead */
|
||||
|
||||
@@ -9,7 +9,7 @@ declare module '../context' {
|
||||
}
|
||||
}
|
||||
|
||||
export class WorkerService extends Service {
|
||||
export default class WorkerService extends Service {
|
||||
private handlers: Record<string, Function> = {};
|
||||
consuming = true;
|
||||
running = null;
|
||||
@@ -85,8 +85,3 @@ export class WorkerService extends Service {
|
||||
await this.promise;
|
||||
}
|
||||
}
|
||||
|
||||
export async function apply(ctx: Context) {
|
||||
ctx.provide('worker', undefined, true);
|
||||
ctx.worker = new WorkerService(ctx);
|
||||
}
|
||||
Reference in new issue
Block a user