Compare commits
2 Commits
ade2861395
...
2fa8f32f44
| Author | SHA1 | Date | |
|---|---|---|---|
| 2fa8f32f44 | |||
| 6e9d58c6e3 |
@@ -9,6 +9,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
63
AS1024.GeoFeed/GeoFeedBuilder/GeoFeedCacheService.cs
Normal file
63
AS1024.GeoFeed/GeoFeedBuilder/GeoFeedCacheService.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using AS1024.GeoFeed.Models;
|
||||
using AS1024.GeoFeed.GeoFeedBuilder;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using AS1024.GeoFeed.Interfaces;
|
||||
|
||||
namespace AS1024.GeoFeed.GeoFeedCacheService
|
||||
{
|
||||
public class GeoFeedCacheService : IHostedService
|
||||
{
|
||||
CancellationToken _cancellationToken;
|
||||
private readonly ILogger<GeoFeedCacheService> logger;
|
||||
private readonly IGeoFeedProvider feedProvider;
|
||||
|
||||
public GeoFeedCacheService(ILogger<GeoFeedCacheService> logger,
|
||||
IGeoFeedProvider feedProvider)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.feedProvider = feedProvider;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_ = StartPerioidicSync();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task<bool> StartPerioidicSync(){
|
||||
List<GeoFeedCacheEntry> geoFeedCacheEntry = [];
|
||||
while (!_cancellationToken.IsCancellationRequested) {
|
||||
await Task.Delay(TimeSpan.FromMinutes(30));
|
||||
logger.LogInformation("Running on disk fallback cache process...");
|
||||
var results = await feedProvider.GetGeoFeedData();
|
||||
|
||||
results.ForEach(x => {
|
||||
geoFeedCacheEntry.Add(new (){
|
||||
Prefix = x.Prefix,
|
||||
GeolocCity = x.GeolocCity,
|
||||
GeolocCountry = x.GeolocCountry,
|
||||
GeolocHasLocation = x.GeolocHasLocation,
|
||||
GeolocPostalCode = x.GeolocPostalCode,
|
||||
GeolocRegion = x.GeolocRegion
|
||||
});
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class GeoFeedCacheEntry : IPGeoFeed {
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GeoFeedCacheDbContext : DbContext {
|
||||
public virtual DbSet<GeoFeedCacheEntry> GeoFeedCacheEntries {get;set;}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user