Skip to content

Commit

Permalink
fix bad db version key
Browse files Browse the repository at this point in the history
  • Loading branch information
aspriddell committed Dec 1, 2024
1 parent b014aab commit 08ba5dd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions DragonFruit.OnionFruit.Web.Worker/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ private async Task PerformUpdate()
var sourceInstances = new Dictionary<Type, IDataSource>();

var redis = scope.ServiceProvider.GetRequiredService<IConnectionMultiplexer>().GetDatabase();
var keyPrefix = _config[RedisClientConfigurator.PrefixConfigKey] ?? RedisClientConfigurator.DefaultKeyPrefix;

var databaseVersionKey = new RedisKey($"{keyPrefix}:{LastDatabaseVersionKey}");
var nextVersion = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

#if !DEBUG
var lastUpdatedValue = await redis.StringGetAsync(LastDatabaseVersionKey).ConfigureAwait(false);
var lastUpdatedValue = await redis.StringGetAsync(databaseVersionKey).ConfigureAwait(false);
var lastVersion = DateTimeOffset.FromUnixTimeSeconds(lastUpdatedValue.HasValue && long.TryParse(lastUpdatedValue.ToString(), out var val) ? val : 0);
#else
// in debug mode, use minvalue to always perform fetch.
Expand Down Expand Up @@ -138,8 +141,7 @@ private async Task PerformUpdate()
_stopwatch.Stop();
_logger.LogInformation("Worker update completed successfully (took {ts})", _stopwatch.Elapsed);

var redisPrefix = _config[RedisClientConfigurator.PrefixConfigKey] ?? RedisClientConfigurator.DefaultKeyPrefix;
await redis.StringSetAsync($"{redisPrefix}:{LastDatabaseVersionKey}", nextVersion, TimeSpan.FromDays(1)).ConfigureAwait(false);
await redis.StringSetAsync(databaseVersionKey, nextVersion, TimeSpan.FromDays(1)).ConfigureAwait(false);
}

private List<GeneratorDescriptor> GetDescriptors(IConfiguration config)
Expand Down

0 comments on commit 08ba5dd

Please sign in to comment.