Introduce TaskScheduler into backends

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2021-12-21 15:00:47 +01:00
parent a85d9fe831
commit 0dcd1dd64f
9 changed files with 71 additions and 7 deletions
+1
View File
@@ -25,6 +25,7 @@
},
"dependencies": {
"@backstage/backend-common": "^0.10.0",
"@backstage/backend-tasks": "^0.1.0",
"@backstage/catalog-client": "^0.5.3",
"@backstage/catalog-model": "^0.9.8",
"@backstage/config": "^0.1.10",
+6 -3
View File
@@ -35,6 +35,7 @@ import {
useHotMemoize,
ServerTokenManager,
} from '@backstage/backend-common';
import { TaskScheduler } from '@backstage/backend-tasks';
import { Config } from '@backstage/config';
import healthcheck from './plugins/healthcheck';
import { metricsInit, metricsHandler } from './metrics';
@@ -68,16 +69,17 @@ function makeCreateEnv(config: Config) {
discovery,
tokenManager,
});
root.info(`Created UrlReader ${reader}`);
const databaseManager = DatabaseManager.fromConfig(config);
const cacheManager = CacheManager.fromConfig(config);
const taskScheduler = TaskScheduler.fromConfig(config);
root.info(`Created UrlReader ${reader}`);
return (plugin: string): PluginEnvironment => {
const logger = root.child({ type: 'plugin', plugin });
const database = databaseManager.forPlugin(plugin);
const cache = cacheManager.forPlugin(plugin);
const scheduler = taskScheduler.forPlugin(plugin);
return {
logger,
cache,
@@ -87,6 +89,7 @@ function makeCreateEnv(config: Config) {
discovery,
tokenManager,
permissions,
scheduler,
};
};
}
+2
View File
@@ -24,6 +24,7 @@ import {
UrlReader,
} from '@backstage/backend-common';
import { ServerPermissionClient } from '@backstage/plugin-permission-node';
import { PluginTaskScheduler } from '@backstage/backend-tasks';
export type PluginEnvironment = {
logger: Logger;
@@ -34,4 +35,5 @@ export type PluginEnvironment = {
discovery: PluginEndpointDiscovery;
tokenManager: TokenManager;
permissions: ServerPermissionClient;
scheduler: PluginTaskScheduler;
};