Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

INT-11156: wrap in try/catch timeout #24

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions src/configuration-manager/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ class MicrosoftConfigurationManagerClient {

const records = result.recordset;

logger.info(`Proccesed ${records.length} records from query`);

if (records.length > 0) {
await pMap(
records,
Expand Down Expand Up @@ -175,37 +173,42 @@ class MicrosoftConfigurationManagerClient {
async listCollectionSubscriptions<T>(
tableName: string,
iteratee: ResourceIteratee<T>,
logger: IntegrationLogger,
pageSize: number = 200,
) {
let offset = 0;
let hasMoreRecords = true;

while (hasMoreRecords) {
const query = buildCollectionSubscriptionQuery(
this.dbName,
tableName,
offset,
pageSize,
);
const result = await this.wrapWithRequestFailedHandler(() =>
this.connection.query(query),
);

const records = result.recordset;
if (records.length > 0) {
await pMap(
records,
async (record) => {
await iteratee(record);
},
{
concurrency: 2,
},
try {
while (hasMoreRecords) {
const query = buildCollectionSubscriptionQuery(
this.dbName,
tableName,
offset,
pageSize,
);
offset += pageSize;
} else {
hasMoreRecords = false;
const result = await this.wrapWithRequestFailedHandler(() =>
this.connection.query(query),
);

const records = result.recordset;
if (records.length > 0) {
await pMap(
records,
async (record) => {
await iteratee(record);
},
{
concurrency: 2,
},
);
offset += pageSize;
} else {
hasMoreRecords = false;
}
}
} catch (err) {
logger.info(`Received SQL error when processing query: ${err}`);
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/steps/collections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ export const fetchCollectionsSteps: IntegrationStep<IntegrationConfig>[] = [
name: 'Build Collection Relationships',
entities: [],
relationships: [Relationships.COLLECTION_HAS_DEVICE],
dependsOn: [Steps.FETCH_COLLECTIONS, Steps.FETCH_DEVICES],
dependsOn: [
Steps.FETCH_COLLECTIONS,
Steps.FETCH_DEVICES,
// INT-11156: this kind of hacky, but we need to await until this steps finishes to avoid overloading the server
Steps.BUILD_APPLICATION_RELATIONSHIPS,
],
executionHandler: buildCollectionsRelationships,
},
];
Expand Down Expand Up @@ -80,6 +85,7 @@ export async function buildCollectionsRelationships({
);
}
},
logger,
);
}
},
Expand Down
Loading