Update task schedule examples

Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
Johan Haals
2022-05-03 13:39:54 +02:00
parent 6d06600d2b
commit f60c94b5cc
9 changed files with 27 additions and 35 deletions
+1 -2
View File
@@ -15,14 +15,13 @@ then make use of its facilities as necessary:
```typescript
import { TaskScheduler } from '@backstage/backend-tasks';
import { Duration } from 'luxon';
const scheduler = TaskScheduler.fromConfig(rootConfig).forPlugin('my-plugin');
await scheduler.scheduleTask({
id: 'refresh_things',
frequency: { cron: '*/5 * * * *' }, // every 5 minutes, also supports Duration
timeout: Duration.fromObject({ minutes: 15 }),
timeout: { minutes: 15 },
fn: async () => {
await entityProvider.run();
},
+3 -4
View File
@@ -26,7 +26,6 @@ import {
} from '@backstage/plugin-search-backend-node';
import { DefaultTechDocsCollatorFactory } from '@backstage/plugin-techdocs-backend';
import { Router } from 'express';
import { Duration } from 'luxon';
import { PluginEnvironment } from '../types';
async function createSearchEngine(
@@ -57,11 +56,11 @@ export default async function createPlugin(
});
const schedule = env.scheduler.createScheduledTaskRunner({
frequency: Duration.fromObject({ minutes: 10 }),
timeout: Duration.fromObject({ minutes: 15 }),
frequency: { seconds: 10 },
timeout: { minutes: 15 },
// A 3 second delay gives the backend server a chance to initialize before
// any collators are executed, which may attempt requests against the API.
initialDelay: Duration.fromObject({ seconds: 3 }),
initialDelay: { seconds: 3 },
});
// Collators are responsible for gathering documents known to plugins. This
@@ -36,7 +36,6 @@
"dockerode": "^3.3.1",
"express": "^4.17.1",
"express-promise-router": "^4.1.0",
"luxon": "^2.0.2",
"pg": "^8.3.0",
"winston": "^3.2.1"
},
@@ -8,7 +8,6 @@ import { PluginEnvironment } from '../types';
import { DefaultCatalogCollatorFactory } from '@backstage/plugin-catalog-backend';
import { DefaultTechDocsCollatorFactory } from '@backstage/plugin-techdocs-backend';
import { Router } from 'express';
import { Duration } from 'luxon';
export default async function createPlugin(
env: PluginEnvironment,
@@ -23,11 +22,11 @@ export default async function createPlugin(
});
const schedule = env.scheduler.createScheduledTaskRunner({
frequency: Duration.fromObject({ minutes: 10 }),
timeout: Duration.fromObject({ minutes: 15 }),
frequency: { minutes: 10 },
timeout: { minutes: 15 },
// A 3 second delay gives the backend server a chance to initialize before
// any collators are executed, which may attempt requests against the API.
initialDelay: Duration.fromObject({ seconds: 3 }),
initialDelay: { seconds: 3 },
});
// Collators are responsible for gathering documents known to plugins. This