chore: Update constructor args to object

Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
Johan Haals
2021-06-11 11:52:37 +02:00
parent 5b721e1ebc
commit 9600e5e669
3 changed files with 19 additions and 13 deletions
@@ -263,11 +263,11 @@ export class NextCatalogBuilder {
const db = new CommonDatabase(dbClient, logger);
const processingDatabase = new DefaultProcessingDatabase(
dbClient,
const processingDatabase = new DefaultProcessingDatabase({
database: dbClient,
logger,
this.refreshIntervalSeconds,
);
refreshIntervalSeconds: this.refreshIntervalSeconds,
});
const integrations = ScmIntegrations.fromConfig(config);
const orchestrator = new DefaultCatalogProcessingOrchestrator({
processors,
@@ -39,7 +39,11 @@ describe('Default Processing Database', () => {
await DatabaseManager.createDatabase(knex);
return {
knex,
db: new DefaultProcessingDatabase(knex, logger, 100),
db: new DefaultProcessingDatabase({
database: knex,
logger,
refreshIntervalSeconds: 100,
}),
};
}
@@ -44,9 +44,11 @@ const BATCH_SIZE = 50;
export class DefaultProcessingDatabase implements ProcessingDatabase {
constructor(
private readonly database: Knex,
private readonly logger: Logger,
private readonly refreshIntervalSeconds: number,
private readonly options: {
database: Knex;
logger: Logger;
refreshIntervalSeconds: number;
},
) {}
async updateProcessedEntity(
@@ -273,7 +275,7 @@ export class DefaultProcessingDatabase implements ProcessingDatabase {
.whereIn('target_entity_ref', toRemove)
.delete();
this.logger.debug(
this.options.logger.debug(
`removed, ${removedCount} entities: ${JSON.stringify(toRemove)}`,
);
}
@@ -379,11 +381,11 @@ export class DefaultProcessingDatabase implements ProcessingDatabase {
next_update_at:
tx.client.config.client === 'sqlite3'
? tx.raw(`datetime('now', ?)`, [
`${this.refreshIntervalSeconds} seconds`,
`${this.options.refreshIntervalSeconds} seconds`,
])
: tx.raw(
`now() + interval '${Number(
this.refreshIntervalSeconds,
this.options.refreshIntervalSeconds,
)} seconds'`,
),
});
@@ -413,7 +415,7 @@ export class DefaultProcessingDatabase implements ProcessingDatabase {
try {
let result: T | undefined = undefined;
await this.database.transaction(
await this.options.database.transaction(
async tx => {
// We can't return here, as knex swallows the return type in case the transaction is rolled back:
// https://github.com/knex/knex/blob/e37aeaa31c8ef9c1b07d2e4d3ec6607e557d800d/lib/transaction.js#L136
@@ -427,7 +429,7 @@ export class DefaultProcessingDatabase implements ProcessingDatabase {
return result!;
} catch (e) {
this.logger.debug(`Error during transaction, ${e}`);
this.options.logger.debug(`Error during transaction, ${e}`);
if (
/SQLITE_CONSTRAINT: UNIQUE/.test(e.message) ||