Skip to content

Commit

Permalink
Merge pull request backstage#27753 from backstage/djam/default-schedules
Browse files Browse the repository at this point in the history
chore: set a default schedule for the GithubEntityProvider
  • Loading branch information
freben authored Nov 21, 2024
2 parents 554388c + 34aa45a commit 928b9ef
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-schools-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend-module-github': patch
---

Pass in a default schedule to the `GithubEntityProvider` if none is provided
Original file line number Diff line number Diff line change
Expand Up @@ -621,22 +621,6 @@ describe('GithubEntityProvider', () => {
).toThrow('Either schedule or scheduler must be provided');
});

it('fail with scheduler but no schedule config', () => {
const scheduler = {
createScheduledTaskRunner: (_: any) => jest.fn(),
} as unknown as SchedulerService;
const config = createSingleProviderConfig();

expect(() =>
GithubEntityProvider.fromConfig(config, {
logger,
scheduler,
}),
).toThrow(
'No schedule provided neither via code nor config for github-provider:myProvider',
);
});

it('single simple provider config with schedule in config', async () => {
const schedule = new PersistingTaskRunner();
const scheduler = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber {
);
}

if (!options.schedule && !providerConfig.schedule) {
throw new Error(
`No schedule provided neither via code nor config for github-provider:${providerConfig.id}.`,
);
}

const taskRunner =
options.schedule ??
options.scheduler!.createScheduledTaskRunner(providerConfig.schedule!);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
*/

import { ConfigReader } from '@backstage/config';
import { readProviderConfigs } from './GithubEntityProviderConfig';
import {
readProviderConfigs,
DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
} from './GithubEntityProviderConfig';

describe('readProviderConfigs', () => {
afterEach(() => jest.resetAllMocks());
Expand Down Expand Up @@ -124,7 +127,7 @@ describe('readProviderConfigs', () => {
},
visibility: undefined,
},
schedule: undefined,
schedule: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
validateLocationsExist: false,
});
expect(providerConfigs[1]).toEqual({
Expand All @@ -142,7 +145,7 @@ describe('readProviderConfigs', () => {
},
visibility: undefined,
},
schedule: undefined,
schedule: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
validateLocationsExist: false,
});
expect(providerConfigs[2]).toEqual({
Expand All @@ -160,7 +163,7 @@ describe('readProviderConfigs', () => {
},
visibility: undefined,
},
schedule: undefined,
schedule: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
validateLocationsExist: false,
});
expect(providerConfigs[3]).toEqual({
Expand All @@ -178,7 +181,7 @@ describe('readProviderConfigs', () => {
},
visibility: undefined,
},
schedule: undefined,
schedule: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
validateLocationsExist: false,
});
expect(providerConfigs[4]).toEqual({
Expand All @@ -196,7 +199,7 @@ describe('readProviderConfigs', () => {
},
visibility: undefined,
},
schedule: undefined,
schedule: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
validateLocationsExist: false,
});
expect(providerConfigs[5]).toEqual({
Expand All @@ -214,7 +217,7 @@ describe('readProviderConfigs', () => {
},
visibility: undefined,
},
schedule: undefined,
schedule: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
validateLocationsExist: false,
});
expect(providerConfigs[6]).toEqual({
Expand All @@ -232,7 +235,7 @@ describe('readProviderConfigs', () => {
},
visibility: ['public', 'internal'],
},
schedule: undefined,
schedule: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
validateLocationsExist: false,
});
expect(providerConfigs[7]).toEqual({
Expand All @@ -251,7 +254,7 @@ describe('readProviderConfigs', () => {
visibility: undefined,
},
validateLocationsExist: false,
schedule: undefined,
schedule: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
});
expect(providerConfigs[8]).toEqual({
id: 'providerWithSchedule',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ import { Config } from '@backstage/config';
const DEFAULT_CATALOG_PATH = '/catalog-info.yaml';
const DEFAULT_PROVIDER_ID = 'default';

export const DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE = {
frequency: {
hours: 3,
},
timeout: {
hours: 1,
},
};

export type GithubEntityProviderConfig = {
id: string;
catalogPath: string;
Expand Down Expand Up @@ -99,7 +108,7 @@ function readProviderConfig(
? readSchedulerServiceTaskScheduleDefinitionFromConfig(
config.getConfig('schedule'),
)
: undefined;
: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE;

return {
id,
Expand Down

0 comments on commit 928b9ef

Please sign in to comment.