tethys.backend/providers/TokenWorkerProvider.ts
Arno Kaimbacher 7915f66dd6 - added earliestPublicationDate for App/Models/Dataset.ts
- new classes TokenWorkerService.ts, TokenWorker.ts and ResumptionToken.ts for using REDIS with paging OAI results
- deletd public/asstes2/langCodeMap.xml: integrated it directly in datasetxml2oai-pmh.xslt
- added redis npm package
- added TokenWorkerProvider.ts for using singleton of TokenWorkerService inside OaiController.ts
- added config/oai.ts for oai related configs from .env-file
- adapted XmlModel.ts for grting domDocument from database
2023-10-03 21:11:02 +02:00

62 lines
2.0 KiB
TypeScript

import type { ApplicationContract } from '@ioc:Adonis/Core/Application';
/*
|--------------------------------------------------------------------------
| Provider
|--------------------------------------------------------------------------
|
| Your application is not ready when this file is loaded by the framework.
| Hence, the top level imports relying on the IoC container will not work.
| You must import them inside the life-cycle methods defined inside
| the provider class.
|
| @example:
|
| public async ready () {
| const Database = this.app.container.resolveBinding('Adonis/Lucid/Database')
| const Event = this.app.container.resolveBinding('Adonis/Core/Event')
| Event.on('db:query', Database.prettyPrint)
| }
|
*/
export default class TokenWorkerProvider {
public static needsApplication = true;
private tokenWorkerInstance; //: TokenWorkerService | null = null;
constructor(protected app: ApplicationContract) {}
public register() {
// Register your own bindings
// Bind TokenWorker to the IoC container
this.app.container.singleton('App/Library/Oai/TokenWorkerContract', () => {
// 1. import the oai configuration
const ttl: number = 86400;
// 2. import our REDIS wrapper class
const TokenWorkerService = require('App/Library/Oai/TokenWorkerSerice').default;
this.tokenWorkerInstance = new TokenWorkerService(ttl);
// 3. return a new instance
return this.tokenWorkerInstance;
});
}
// public async boot() {
// // All bindings are ready, feel free to use them
// // optionally do some initial setup
// }
// public async ready() {
// // App is ready
// }
public async shutdown() {
console.log('TokenServerProvider shutdown()');
// Cleanup, since app is going down
if (this.tokenWorkerInstance) {
// Call the disconnect method when the application is shutting down
await this.tokenWorkerInstance.close();
}
}
}