fix: load data source when data source load failed (#3793)
This commit is contained in:
parent
9354e25d74
commit
4e145a8868
@ -14,6 +14,7 @@ export class DataSourceManager {
|
||||
}
|
||||
|
||||
async add(dataSource: DataSource, options: any = {}) {
|
||||
console.log('add', dataSource.name, options);
|
||||
await dataSource.load(options);
|
||||
this.dataSources.set(dataSource.name, dataSource);
|
||||
}
|
||||
|
@ -342,9 +342,10 @@ describe('data source', async () => {
|
||||
expect(app.dataSourceManager.dataSources.get('mockInstance1')).not.toBeDefined();
|
||||
});
|
||||
|
||||
class MockCollectionManager extends CollectionManager {}
|
||||
|
||||
describe('data source collections', () => {
|
||||
beforeEach(async () => {
|
||||
class MockCollectionManager extends CollectionManager {}
|
||||
class MockDataSource extends DataSource {
|
||||
async load(): Promise<void> {
|
||||
this.collectionManager.defineCollection({
|
||||
@ -397,6 +398,7 @@ describe('data source', async () => {
|
||||
const listResp = await app.agent().resource('dataSources').list({
|
||||
appends: 'collections',
|
||||
});
|
||||
|
||||
expect(listResp.status).toBe(200);
|
||||
|
||||
const listEnabledResp = await app.agent().resource('dataSources').listEnabled({});
|
||||
@ -406,6 +408,41 @@ describe('data source', async () => {
|
||||
expect(item.collections).toBeDefined();
|
||||
});
|
||||
|
||||
it('should get data source with collections when data source load failed', async () => {
|
||||
class MockDataSource2 extends DataSource {
|
||||
async load(): Promise<void> {
|
||||
throw new Error('load failed');
|
||||
}
|
||||
|
||||
createCollectionManager(options?: any) {
|
||||
return new MockCollectionManager();
|
||||
}
|
||||
}
|
||||
|
||||
app.dataSourceManager.factory.register('mock2', MockDataSource2);
|
||||
|
||||
await app.db.getRepository('dataSources').create({
|
||||
values: {
|
||||
key: 'mockInstance2',
|
||||
type: 'mock2',
|
||||
displayName: 'Mock 2',
|
||||
options: {
|
||||
password: '123456',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await waitSecond(1000);
|
||||
|
||||
const listResp = await app.agent().resource('dataSources').listEnabled({
|
||||
appends: 'collections',
|
||||
});
|
||||
|
||||
expect(listResp.status).toBe(200);
|
||||
|
||||
console.log(listResp.body.data);
|
||||
});
|
||||
|
||||
it('should get collections from datasource', async () => {
|
||||
const listResp = await app.agent().resource('dataSources').list();
|
||||
expect(listResp.status).toBe(200);
|
||||
|
@ -159,15 +159,14 @@ export class PluginDataSourceManagerServer extends Plugin {
|
||||
const dataSource = app.dataSourceManager.dataSources.get(dataSourceModel.get('key'));
|
||||
const dataSourceStatus = plugin.dataSourceStatus[dataSourceModel.get('key')];
|
||||
|
||||
// @ts-ignore
|
||||
const isDBInstance = !!dataSource.collectionManager.db;
|
||||
|
||||
const item: any = {
|
||||
key: dataSourceModel.get('key'),
|
||||
displayName: dataSourceModel.get('displayName'),
|
||||
status: dataSourceStatus,
|
||||
type: dataSourceModel.get('type'),
|
||||
isDBInstance,
|
||||
|
||||
// @ts-ignore
|
||||
isDBInstance: !!dataSource?.collectionManager.db,
|
||||
};
|
||||
|
||||
if (dataSourceStatus === 'loading-failed' || dataSourceStatus === 'reloading-failed') {
|
||||
|
Loading…
Reference in New Issue
Block a user