Skip to content

Commit

Permalink
chore: Parse Last Modified timestamp to ensure new configs only (#156)
Browse files Browse the repository at this point in the history
* last modified parse timestamp

* Set config if last modified header is not set.
  • Loading branch information
JamieSinn authored Jul 25, 2024
1 parent 5e07726 commit b1cb014
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,30 @@ private async Task FetchConfigAsyncWithTask()
{
try
{
localBucketing.StoreConfig(sdkKey, res.Content);
var etag = res.Headers?.FirstOrDefault(e => e.Name?.ToLower() == "etag");
var lastModified = res.Headers?.FirstOrDefault(e => e.Name?.ToLower() == "last-modified");
var etag = res.Headers?.FirstOrDefault(e => e.Name?.ToLower() == "etag");
if (configLastModified != "" && lastModified != null && (string)lastModified.Value != "")
{
var parsedHeader = Convert.ToDateTime((string)lastModified.Value);
var storedHeader = Convert.ToDateTime(configLastModified);
// negative means that the stored header is before the returned parsed header
if (DateTime.Compare(storedHeader, parsedHeader) >= 0)
{
logger.LogWarning("Received timestamp on last-modified that was before the stored one. Not updating config.");
return;
}
}

localBucketing.StoreConfig(sdkKey, res.Content);
configEtag = (string)etag?.Value;
configLastModified = (string)lastModified?.Value;
logger.LogDebug("Config successfully initialized with etag: {ConfigEtag}, {lastmodified}", configEtag, configLastModified);
eventQueue?.QueueSDKConfigEvent(request, res);
}
catch (WasmtimeException e)
catch (Exception e)
{
// This is to catch any exception that is thrown by the SetConfig method if the config is not valid
logger.LogError($"Failed to set config: {e.InnerException?.Message}");
logger.LogError($"Failed to set config: {e.Message} {e.InnerException.Message}");
}
}
}
Expand Down

0 comments on commit b1cb014

Please sign in to comment.