Skip to content

Commit 2d8d734

Browse files
dgandhi62gandhyakaizencc
authored
refactor(cli): property bag for refreshStacks function (#855)
The refreshStacks function currently takes 4 individual parameters, making it difficult to maintain as new parameters are added. This change: - Introduces a `RefreshStacksProps` interface to group function parameters - Refactors the `refreshStacks` function signature to accept a single props object --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license Co-authored-by: Dhyan Gandhi <[email protected]> Co-authored-by: Kaizen Conroy <[email protected]>
1 parent e0ef8d0 commit 2d8d734

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

packages/@aws-cdk/toolkit-lib/lib/api/garbage-collection/garbage-collector.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,12 @@ export class GarbageCollector {
219219
const activeAssets = new ActiveAssetCache();
220220

221221
// Grab stack templates first
222-
await refreshStacks(cfn, this.ioHelper, activeAssets, qualifier);
222+
await refreshStacks({
223+
cfn,
224+
ioHelper: this.ioHelper,
225+
activeAssets,
226+
qualifier,
227+
});
223228
// Start the background refresh
224229
const backgroundStackRefresh = new BackgroundStackRefresh({
225230
cfn,

packages/@aws-cdk/toolkit-lib/lib/api/garbage-collection/stack-refresh.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,18 @@ function bootstrapFilter(parameters?: ParameterDeclaration[], qualifier?: string
9797
splitBootstrapVersion[2] != qualifier);
9898
}
9999

100-
export async function refreshStacks(cfn: ICloudFormationClient, ioHelper: IoHelper, activeAssets: ActiveAssetCache, qualifier?: string) {
100+
export interface RefreshStacksProps {
101+
readonly cfn: ICloudFormationClient;
102+
readonly ioHelper: IoHelper;
103+
readonly activeAssets: ActiveAssetCache;
104+
readonly qualifier?: string;
105+
}
106+
107+
export async function refreshStacks(props: RefreshStacksProps) {
101108
try {
102-
const stacks = await fetchAllStackTemplates(cfn, ioHelper, qualifier);
109+
const stacks = await fetchAllStackTemplates(props.cfn, props.ioHelper, props.qualifier);
103110
for (const stack of stacks) {
104-
activeAssets.rememberStack(stack);
111+
props.activeAssets.rememberStack(stack);
105112
}
106113
} catch (err) {
107114
throw new ToolkitError(`Error refreshing stacks: ${err}`);
@@ -154,7 +161,12 @@ export class BackgroundStackRefresh {
154161
private async refresh() {
155162
const startTime = Date.now();
156163

157-
await refreshStacks(this.props.cfn, this.props.ioHelper, this.props.activeAssets, this.props.qualifier);
164+
await refreshStacks({
165+
cfn: this.props.cfn,
166+
ioHelper: this.props.ioHelper,
167+
activeAssets: this.props.activeAssets,
168+
qualifier: this.props.qualifier,
169+
});
158170
this.justRefreshedStacks();
159171

160172
// If the last invocation of refreshStacks takes <5 minutes, the next invocation starts 5 minutes after the last one started.

0 commit comments

Comments
 (0)