Skip to content

Commit

Permalink
fix: Better error handling in vm scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
adityachoudhari26 committed Jan 20, 2025
1 parent d96faab commit 2de6509
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions apps/event-worker/src/resource-scan/google/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,36 +121,35 @@ export const getGoogleVMResources = async (
{ workspaceId: workspace.id, config, googleServiceAccountEmail },
);

return Promise.allSettled(
return Promise.all(
config.projectIds.map(async (projectId) => {
const allResources: SCHEMA.InsertResource[] = [];
for await (const [_, instances] of vmClient.aggregatedListAsync({
project: projectId,
returnPartialSuccess: true,
})) {
if (instances.instances == null || instances.instances.length === 0)
continue;
const resources = instances.instances.map((instance) =>
instanceToResource(
instance,
workspace.id,
config.resourceProviderId,
projectId,
),
try {
const allResources: SCHEMA.InsertResource[] = [];
for await (const [_, instances] of vmClient.aggregatedListAsync({
project: projectId,
returnPartialSuccess: true,
})) {
if (instances.instances == null || instances.instances.length === 0)
continue;
const resources = instances.instances.map((instance) =>
instanceToResource(
instance,
workspace.id,
config.resourceProviderId,
projectId,
),
);
allResources.push(...resources);
}

return allResources;
} catch (error: any) {
log.error(
`Unable to list VMs for provider ${config.id} and project ${projectId}: ${error.message}`,
{ error, projectId, providerId: config.resourceProviderId },
);
allResources.push(...resources);
return [];
}

return allResources;
}),
).then((results) =>
results.flatMap((result) => {
if (result.status === "fulfilled") return result.value;
log.error(
`Unable to list VMs for provider ${config.id}: ${result.reason}`,
{ error: result.reason },
);
return [];
}),
);
).then((results) => results.flat());
};

0 comments on commit 2de6509

Please sign in to comment.