@@ -14,11 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
DatabaseManager,
|
||||
getRootLogger,
|
||||
PluginDatabaseManager,
|
||||
} from '@backstage/backend-common';
|
||||
import { DatabaseManager, getRootLogger } from '@backstage/backend-common';
|
||||
import { Config } from '@backstage/config';
|
||||
import { once } from 'lodash';
|
||||
import { Duration } from 'luxon';
|
||||
@@ -60,15 +56,9 @@ export class TaskScheduler {
|
||||
* @param pluginId - The unique ID of the plugin, for example "catalog"
|
||||
* @returns A {@link PluginTaskScheduler} instance
|
||||
*/
|
||||
forPlugin(
|
||||
pluginId: string,
|
||||
options?: { databaseManager?: PluginDatabaseManager; logger?: Logger },
|
||||
): PluginTaskScheduler {
|
||||
const databaseManager =
|
||||
options?.databaseManager ?? this.databaseManager.forPlugin(pluginId);
|
||||
const logger = options?.logger ?? this.logger.child({ plugin: pluginId });
|
||||
|
||||
forPlugin(pluginId: string): PluginTaskScheduler {
|
||||
const databaseFactory = once(async () => {
|
||||
const databaseManager = this.databaseManager.forPlugin(pluginId);
|
||||
const knex = await databaseManager.getClient();
|
||||
|
||||
if (!databaseManager.migrations?.skip) {
|
||||
@@ -78,13 +68,16 @@ export class TaskScheduler {
|
||||
const janitor = new PluginTaskSchedulerJanitor({
|
||||
knex,
|
||||
waitBetweenRuns: Duration.fromObject({ minutes: 1 }),
|
||||
logger,
|
||||
logger: this.logger,
|
||||
});
|
||||
janitor.start();
|
||||
|
||||
return knex;
|
||||
});
|
||||
|
||||
return new PluginTaskSchedulerImpl(databaseFactory, logger);
|
||||
return new PluginTaskSchedulerImpl(
|
||||
databaseFactory,
|
||||
this.logger.child({ plugin: pluginId }),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user