diff --git a/.changeset/many-tools-buy.md b/.changeset/many-tools-buy.md new file mode 100644 index 0000000000..c2a617edfd --- /dev/null +++ b/.changeset/many-tools-buy.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-tasks': patch +--- + +Relaxed the task ID requirement to now support any non-empty string diff --git a/packages/backend-tasks/src/tasks/util.test.ts b/packages/backend-tasks/src/tasks/util.test.ts index f74669a7f4..614de8c6c8 100644 --- a/packages/backend-tasks/src/tasks/util.test.ts +++ b/packages/backend-tasks/src/tasks/util.test.ts @@ -20,14 +20,14 @@ import { delegateAbortController, sleep, validateId } from './util'; describe('util', () => { describe('validateId', () => { - it.each(['a', 'a_b', 'ab123c_2'])( + it.each(['a', 'a_b', 'ab123c_2', 'a!', 'A', 'a-b', 'a.b', '_a', 'a_'])( 'accepts valid inputs, %p', async input => { expect(validateId(input)).toBeUndefined(); }, ); - it.each(['', 'a!', 'A', 'a-b', 'a.b', '_a', 'a_', null, Symbol('a')])( + it.each(['', null, Symbol('a')])( 'rejects invalid inputs, %p', async input => { expect(() => validateId(input as any)).toThrow(); diff --git a/packages/backend-tasks/src/tasks/util.ts b/packages/backend-tasks/src/tasks/util.ts index 0509f29363..829515d721 100644 --- a/packages/backend-tasks/src/tasks/util.ts +++ b/packages/backend-tasks/src/tasks/util.ts @@ -19,12 +19,10 @@ import { Knex } from 'knex'; import { DateTime, Duration } from 'luxon'; import { AbortController, AbortSignal } from 'node-abort-controller'; -// Keep the IDs compatible with e.g. Prometheus +// Keep the IDs compatible with e.g. Prometheus labels export function validateId(id: string) { - if (typeof id !== 'string' || !/^[a-z0-9]+(?:_[a-z0-9]+)*$/.test(id)) { - throw new InputError( - `${id} is not a valid ID, expected string of lowercase characters and digits separated by underscores`, - ); + if (typeof id !== 'string' || !id.trim()) { + throw new InputError(`${id} is not a valid ID, expected non-empty string`); } } diff --git a/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts b/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts index f7d07a15af..bad3941767 100644 --- a/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts +++ b/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts @@ -217,7 +217,7 @@ export class LdapOrgEntityProvider implements EntityProvider { } this.scheduleFn = async () => { - const id = this.getScheduledTaskId(); + const id = `${this.getProviderName()}:refresh`; await schedule.run({ id, fn: async () => { @@ -236,12 +236,6 @@ export class LdapOrgEntityProvider implements EntityProvider { }); }; } - - // Gets a suitable scheduler task ID for this provider instance - private getScheduledTaskId(): string { - const rawId = `refresh_${this.getProviderName()}`; - return rawId.toLocaleLowerCase('en-US').replace(/[^a-z0-9]/g, '_'); - } } // Helps wrap the timing and logging behaviors