From 74663277fb371b01e989e08bc33a352b93ac2930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Mon, 7 Mar 2022 15:32:13 +0100 Subject: [PATCH] rename to createScheduledTaskRunner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .changeset/new-books-protect.md | 2 +- docs/integrations/ldap/org.md | 2 +- packages/backend-tasks/api-report.md | 4 ++-- .../src/tasks/PluginTaskSchedulerImpl.test.ts | 4 ++-- .../src/tasks/PluginTaskSchedulerImpl.ts | 4 ++-- packages/backend-tasks/src/tasks/index.ts | 2 +- packages/backend-tasks/src/tasks/types.ts | 7 ++++--- plugins/catalog-backend-module-ldap/api-report.md | 4 ++-- .../src/processors/LdapOrgEntityProvider.ts | 15 ++++++++++----- 9 files changed, 25 insertions(+), 19 deletions(-) diff --git a/.changeset/new-books-protect.md b/.changeset/new-books-protect.md index 2a561b5e5c..568710ccd0 100644 --- a/.changeset/new-books-protect.md +++ b/.changeset/new-books-protect.md @@ -21,7 +21,7 @@ All things said, a typical setup might now look as follows: + id: 'our-ldap-master', + target: 'ldaps://ds.example.net', + logger: env.logger, -+ schedule: env.scheduler.createTaskSchedule({ ++ schedule: env.scheduler.createScheduledTaskRunner({ + frequency: Duration.fromObject({ minutes: 60 }), + timeout: Duration.fromObject({ minutes: 15 }), + }), diff --git a/docs/integrations/ldap/org.md b/docs/integrations/ldap/org.md index b0fa2ca76d..f7f4e25b1a 100644 --- a/docs/integrations/ldap/org.md +++ b/docs/integrations/ldap/org.md @@ -49,7 +49,7 @@ schedule it: + id: 'our-ldap-master', + target: 'ldaps://ds.example.net', + logger: env.logger, -+ schedule: env.scheduler.createTaskSchedule({ ++ schedule: env.scheduler.createScheduledTaskRunner({ + frequency: Duration.fromObject({ minutes: 60 }), + timeout: Duration.fromObject({ minutes: 15 }), + }), diff --git a/packages/backend-tasks/api-report.md b/packages/backend-tasks/api-report.md index db4dee0c65..98199a55b0 100644 --- a/packages/backend-tasks/api-report.md +++ b/packages/backend-tasks/api-report.md @@ -11,7 +11,7 @@ import { Logger } from 'winston'; // @public export interface PluginTaskScheduler { - createTaskSchedule(schedule: TaskScheduleDefinition): TaskSchedule; + createScheduledTaskRunner(schedule: TaskScheduleDefinition): TaskRunner; scheduleTask( task: TaskScheduleDefinition & TaskInvocationDefinition, ): Promise; @@ -30,7 +30,7 @@ export interface TaskInvocationDefinition { } // @public -export interface TaskSchedule { +export interface TaskRunner { run(task: TaskInvocationDefinition): Promise; } diff --git a/packages/backend-tasks/src/tasks/PluginTaskSchedulerImpl.test.ts b/packages/backend-tasks/src/tasks/PluginTaskSchedulerImpl.test.ts index 0a811a5b88..993041bed4 100644 --- a/packages/backend-tasks/src/tasks/PluginTaskSchedulerImpl.test.ts +++ b/packages/backend-tasks/src/tasks/PluginTaskSchedulerImpl.test.ts @@ -62,7 +62,7 @@ describe('PluginTaskManagerImpl', () => { // This is just to test the wrapper code; most of the actual tests are in // TaskWorker.test.ts - describe('createTaskSchedule', () => { + describe('createScheduledTaskRunner', () => { it.each(databases.eachSupportedId())( 'can run the happy path, %p', async databaseId => { @@ -70,7 +70,7 @@ describe('PluginTaskManagerImpl', () => { const fn = jest.fn(); await manager - .createTaskSchedule({ + .createScheduledTaskRunner({ timeout: Duration.fromMillis(5000), frequency: Duration.fromMillis(5000), }) diff --git a/packages/backend-tasks/src/tasks/PluginTaskSchedulerImpl.ts b/packages/backend-tasks/src/tasks/PluginTaskSchedulerImpl.ts index b410e4d3b5..8d50298ffd 100644 --- a/packages/backend-tasks/src/tasks/PluginTaskSchedulerImpl.ts +++ b/packages/backend-tasks/src/tasks/PluginTaskSchedulerImpl.ts @@ -20,7 +20,7 @@ import { TaskWorker } from './TaskWorker'; import { PluginTaskScheduler, TaskInvocationDefinition, - TaskSchedule, + TaskRunner, TaskScheduleDefinition, } from './types'; import { validateId } from './util'; @@ -55,7 +55,7 @@ export class PluginTaskSchedulerImpl implements PluginTaskScheduler { ); } - createTaskSchedule(schedule: TaskScheduleDefinition): TaskSchedule { + createScheduledTaskRunner(schedule: TaskScheduleDefinition): TaskRunner { return { run: async task => { await this.scheduleTask({ ...task, ...schedule }); diff --git a/packages/backend-tasks/src/tasks/index.ts b/packages/backend-tasks/src/tasks/index.ts index d925f089e8..f6695a8d73 100644 --- a/packages/backend-tasks/src/tasks/index.ts +++ b/packages/backend-tasks/src/tasks/index.ts @@ -19,6 +19,6 @@ export type { PluginTaskScheduler, TaskFunction, TaskInvocationDefinition, - TaskSchedule, + TaskRunner, TaskScheduleDefinition, } from './types'; diff --git a/packages/backend-tasks/src/tasks/types.ts b/packages/backend-tasks/src/tasks/types.ts index 3e46acf55e..35b5598700 100644 --- a/packages/backend-tasks/src/tasks/types.ts +++ b/packages/backend-tasks/src/tasks/types.ts @@ -103,7 +103,7 @@ export interface TaskInvocationDefinition { * * @public */ -export interface TaskSchedule { +export interface TaskRunner { /** * Takes the schedule and executes an actual task using it. * @@ -136,7 +136,8 @@ export interface PluginTaskScheduler { ): Promise; /** - * Creates a task schedule, ready to be invoked at a later time. + * Creates a scheduled but dormant recurring task, ready to be launched at a + * later time. * * @remarks * @@ -146,7 +147,7 @@ export interface PluginTaskScheduler { * * @param schedule - The task schedule */ - createTaskSchedule(schedule: TaskScheduleDefinition): TaskSchedule; + createScheduledTaskRunner(schedule: TaskScheduleDefinition): TaskRunner; } function isValidOptionalDurationString(d: string | undefined): boolean { diff --git a/plugins/catalog-backend-module-ldap/api-report.md b/plugins/catalog-backend-module-ldap/api-report.md index 25f479f73c..edeef4cb82 100644 --- a/plugins/catalog-backend-module-ldap/api-report.md +++ b/plugins/catalog-backend-module-ldap/api-report.md @@ -15,7 +15,7 @@ import { LocationSpec } from '@backstage/plugin-catalog-backend'; import { Logger } from 'winston'; import { SearchEntry } from 'ldapjs'; import { SearchOptions } from 'ldapjs'; -import { TaskSchedule } from '@backstage/backend-tasks'; +import { TaskRunner } from '@backstage/backend-tasks'; import { UserEntity } from '@backstage/catalog-model'; // @public @@ -119,7 +119,7 @@ export interface LdapOrgEntityProviderOptions { groupTransformer?: GroupTransformer; id: string; logger: Logger; - schedule: 'manual' | TaskSchedule; + schedule: 'manual' | TaskRunner; target: string; userTransformer?: UserTransformer; } diff --git a/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts b/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts index 9c483c7b94..f7d07a15af 100644 --- a/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts +++ b/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { TaskSchedule } from '@backstage/backend-tasks'; +import { TaskRunner } from '@backstage/backend-tasks'; import { ANNOTATION_LOCATION, ANNOTATION_ORIGIN_LOCATION, @@ -69,11 +69,16 @@ export interface LdapOrgEntityProviderOptions { /** * The refresh schedule to use. * - * If you pass in 'manual', you are responsible for calling the `read` - * method manually at some interval. If not, it will be automatically - * called regularly with the given schedule using the scheduler. + * @remarks + * + * If you pass in 'manual', you are responsible for calling the `read` method + * manually at some interval. + * + * But more commonly you will pass in the result of + * {@link @backstage/backend-tasks#PluginTaskScheduler.createScheduledTaskRunner} + * to enable automatic scheduling of tasks. */ - schedule: 'manual' | TaskSchedule; + schedule: 'manual' | TaskRunner; /** * The function that transforms a user entry in LDAP to an entity.