Skip to content

Commit 809e763

Browse files
committed
Added WaitForReloadToComplete method for Lambda functions to call so that the config is reloaded before the Lambda compute environment is frozen.
1 parent 9f29bd2 commit 809e763

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/Amazon.Extensions.Configuration.SystemsManager/SystemsManagerConfigurationProvider.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class SystemsManagerConfigurationProvider : ConfigurationProvider
3535
private ISystemsManagerProcessor SystemsManagerProcessor { get; }
3636
private IParameterProcessor ParameterProcessor { get; }
3737

38+
private ManualResetEvent ReloadTaskEvent { get; } = new ManualResetEvent(true);
39+
3840
/// <inheritdoc />
3941
/// <summary>
4042
/// Initializes a new instance with the specified source.
@@ -66,10 +68,33 @@ public SystemsManagerConfigurationProvider(SystemsManagerConfigurationSource sou
6668
var cancellationTokenSource = new CancellationTokenSource(source.ReloadAfter.Value);
6769
var cancellationChangeToken = new CancellationChangeToken(cancellationTokenSource.Token);
6870
return cancellationChangeToken;
69-
}, async () => await LoadAsync(true).ConfigureAwait(false));
71+
}, async () =>
72+
{
73+
ReloadTaskEvent.Reset();
74+
try
75+
{
76+
await LoadAsync(true).ConfigureAwait(false);
77+
}
78+
finally
79+
{
80+
ReloadTaskEvent.Set();
81+
}
82+
});
7083
}
7184
}
7285

86+
/// <summary>
87+
/// If this configuration provider is currently performing a reload of the config data this method will block until
88+
/// the reload is called.
89+
///
90+
/// This method is not meant for general use. It is exposed so a Lambda function can wait for the reload to complete
91+
/// before completing the event causing the Lambda compute environment to be frozen.
92+
/// </summary>
93+
public void WaitForReloadToComplete(TimeSpan timeout)
94+
{
95+
ReloadTaskEvent.WaitOne(timeout);
96+
}
97+
7398
/// <inheritdoc />
7499
/// <summary>
75100
/// Loads the AWS Systems Manager Parameters.

0 commit comments

Comments
 (0)