Compare commits
4 Commits
no-cache
...
2fa8f32f44
| Author | SHA1 | Date | |
|---|---|---|---|
| 2fa8f32f44 | |||
| 6e9d58c6e3 | |||
| ade2861395 | |||
| 4ea9f2ca7f |
@@ -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;}
|
||||
}
|
||||
}
|
||||
16
README.md
16
README.md
@@ -21,6 +21,18 @@ The application requires the following configuration variables to be set:
|
||||
|
||||
These variables can be set in your application's configuration file or through environment variables, depending on your deployment strategy.
|
||||
|
||||
## NetBox Custom Fields
|
||||
|
||||
Ensure that your NetBox instance is configured with the following custom fields:
|
||||
|
||||
- `geoloc_city`: (Text) Represents the city and is not required to be filled in.
|
||||
- `geoloc_country`: (Selection) Represents the country and is not required to be filled in.
|
||||
- `geoloc_has_location`: (Boolean) Indicates if there is geolocation data available and is required.
|
||||
- `geoloc_postal_code`: (Text) Represents the postal code and is not required to be filled in.
|
||||
- `geoloc_region`: (Selection) Represents the region and is not required to be filled in.
|
||||
|
||||
These fields are critical for the application to accurately retrieve and format geolocation data.
|
||||
|
||||
## Getting Started
|
||||
|
||||
To build and run the application, follow these steps:
|
||||
@@ -32,10 +44,6 @@ To build and run the application, follow these steps:
|
||||
5. After a successful build, you can start the application by running `dotnet run`.
|
||||
6. The application will start, and you can access the endpoints as specified.
|
||||
|
||||
## Docker Build
|
||||
|
||||
A Dockerfile is provided for your convienence. This has not been tested as of yet.
|
||||
|
||||
## Endpoints
|
||||
|
||||
The application provides the following key endpoints:
|
||||
|
||||
Reference in New Issue
Block a user