Skip to content

Commit dc25813

Browse files
Copilotazaslonov
andauthored
refactor: share tier labels, add retriedResources to JSON, tidy retry attribution (Closes #162)
Co-authored-by: azaslonov <2320302+azaslonov@users.noreply.github.com>
1 parent a4a5536 commit dc25813

4 files changed

Lines changed: 25 additions & 32 deletions

File tree

‎src/cli/extract-command.ts‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { ArtifactStore } from '../clients/artifact-store.js';
2121
import { IArtifactStore } from '../clients/iartifact-store.js';
2222
import { getCloudConfig, buildArmBaseUrl } from '../lib/cloud-config.js';
2323
import { EXIT_FATAL, EXIT_SUCCESS } from '../lib/exit-codes.js';
24-
import { getResourceTier } from '../lib/dependency-graph.js';
24+
import { getResourceTier, TIER_LABELS } from '../lib/dependency-graph.js';
2525
import { formatDuration } from '../lib/format-duration.js';
2626
import { ResourceType } from '../models/resource-types.js';
2727

@@ -223,21 +223,12 @@ function outputJson(result: ExtractionResult, elapsedMs: number): void {
223223
process.stdout.write(JSON.stringify(output, null, 2) + '\n');
224224
}
225225

226-
/**
227-
* Human-readable labels for each dependency tier, used to group output.
228-
*/
229-
const TIER_LABELS: Record<number, string> = {
230-
1: 'Independent resources',
231-
2: 'Resources with dependencies',
232-
3: 'Child resources',
233-
4: 'Nested child resources',
234-
};
235226

236227
function tierOf(type: ResourceType): number {
237228
try {
238229
return getResourceTier(type);
239230
} catch {
240-
return 0;
231+
return Number.MAX_SAFE_INTEGER;
241232
}
242233
}
243234

‎src/cli/publish-command.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ function outputJson(result: PublishResult): void {
204204
totalErrors: number;
205205
totalSkipped: number;
206206
totalRetries: number;
207+
retriedResources: number;
207208
elapsedMs?: number;
208209
};
209210
actions: Array<{
@@ -243,6 +244,7 @@ function outputJson(result: PublishResult): void {
243244
totalErrors: result.totalErrors,
244245
totalSkipped: result.totalSkipped,
245246
totalRetries: result.totalRetries ?? 0,
247+
retriedResources: result.retriedResources ?? 0,
246248
elapsedMs: result.elapsedMs,
247249
},
248250
actions: result.actions.map((action) => ({

‎src/lib/dependency-graph.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ export const TIER_4_RESOURCES: ResourceType[] = [
109109
ResourceType.GraphQLResolverPolicy,
110110
];
111111

112+
/**
113+
* Human-readable labels for each dependency tier, used to group CLI output.
114+
*/
115+
export const TIER_LABELS: Readonly<Record<number, string>> = {
116+
1: 'Independent resources',
117+
2: 'Resources with dependencies',
118+
3: 'Child resources',
119+
4: 'Nested child resources',
120+
};
121+
112122
/**
113123
* Returns all resource types in topological order (dependencies first).
114124
* This is the order in which resources should be extracted and published.

‎src/services/publish-service.ts‎

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { IArtifactStore } from '../clients/iartifact-store.js';
1111
import { FilterConfig, PublishConfig, OverrideConfig } from '../models/config.js';
1212
import { ApimServiceContext, ResourceDescriptor } from '../models/types.js';
1313
import { ResourceType } from '../models/resource-types.js';
14-
import { getResourceTier } from '../lib/dependency-graph.js';
14+
import { getResourceTier, TIER_LABELS } from '../lib/dependency-graph.js';
1515
import { runParallel } from '../lib/parallel-runner.js';
1616
import { logger } from '../lib/logger.js';
1717
import { isAutoGeneratedId } from '../lib/auto-generated.js';
@@ -89,16 +89,6 @@ export interface PublishResult {
8989
retriedResources?: number;
9090
}
9191

92-
/**
93-
* Human-readable labels for each dependency tier, used in publish output headers.
94-
*/
95-
const TIER_LABELS: Record<number, string> = {
96-
1: 'Independent resources',
97-
2: 'Resources with dependencies',
98-
3: 'Child resources',
99-
4: 'Nested child resources',
100-
};
101-
10292
interface PublishTargets {
10393
targetDescriptors: ResourceDescriptor[];
10494
deletedDescriptors: ResourceDescriptor[];
@@ -811,11 +801,6 @@ async function publishTier(
811801
descriptors: ResourceDescriptor[],
812802
allTargetDescriptors: ResourceDescriptor[]
813803
): Promise<PublishActionResult[]> {
814-
const tasks = descriptors.map((descriptor) => async () => {
815-
const { value, retries } = await trackRetries(() => publishDescriptor(descriptor));
816-
return attachRetries(value, retries);
817-
});
818-
819804
const publishDescriptor = async (descriptor: ResourceDescriptor): Promise<PublishActionResult[]> => {
820805
try {
821806
let publishResult: ResourcePublishResult;
@@ -867,6 +852,11 @@ async function publishTier(
867852
}
868853
};
869854

855+
const tasks = descriptors.map((descriptor) => async () => {
856+
const { value, retries } = await trackRetries(() => publishDescriptor(descriptor));
857+
return attachRetries(value, retries);
858+
});
859+
870860
const taskResults = await runParallel(tasks, 5);
871861

872862
return taskResults.flatMap((tr, index) => {
@@ -1028,11 +1018,6 @@ async function deleteTier(
10281018
config: PublishConfig,
10291019
descriptorsAreDeployed: boolean
10301020
): Promise<PublishActionResult[]> {
1031-
const tasks = descriptors.map((descriptor) => async () => {
1032-
const { value, retries } = await trackRetries(() => deleteDescriptor(descriptor));
1033-
return retries > 0 ? { ...value, retries } : value;
1034-
});
1035-
10361021
const deleteDescriptor = async (descriptor: ResourceDescriptor): Promise<PublishActionResult> => {
10371022
try {
10381023
const deployedDescriptor = config.envMapping && !descriptorsAreDeployed
@@ -1071,6 +1056,11 @@ async function deleteTier(
10711056
}
10721057
};
10731058

1059+
const tasks = descriptors.map((descriptor) => async () => {
1060+
const { value, retries } = await trackRetries(() => deleteDescriptor(descriptor));
1061+
return attachRetries([value], retries)[0] ?? value;
1062+
});
1063+
10741064
const taskResults = await runParallel(tasks, 5);
10751065

10761066
return taskResults.map((tr, index) => {

0 commit comments

Comments
 (0)