aboutsummaryrefslogtreecommitdiff
path: root/BartService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'BartService.cs')
-rw-r--r--BartService.cs18
1 files changed, 17 insertions, 1 deletions
diff --git a/BartService.cs b/BartService.cs
index 3238e09..77a8e5a 100644
--- a/BartService.cs
+++ b/BartService.cs
@@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema;
using System.Security.Cryptography;
using System.Text.Json;
using System.Text.Json.Serialization;
+using System.Timers;
namespace PagerParser {
public partial class PagerContext {
@@ -79,6 +80,9 @@ namespace PagerParser.Bart {
private const string AvailabilityEndpointUrl =
@"https://bartapp.net/webapp/webservice/WebsiteService.svc/GetUserAvailabilityList";
+ private readonly TimeSpan FetchInterval =
+ TimeSpan.FromMinutes(5);
+
private IConfiguration config;
private ILogger logger;
private IServiceProvider serviceProvider;
@@ -87,6 +91,8 @@ namespace PagerParser.Bart {
private HttpClient httpClient;
+ private System.Timers.Timer fetchTimer;
+
public BartService(
IConfiguration config,
ILogger<BartService> logger,
@@ -95,6 +101,11 @@ namespace PagerParser.Bart {
this.config = config;
this.logger = logger;
this.serviceProvider = serviceProvider;
+
+ fetchTimer = new() {
+ Interval = FetchInterval.TotalMilliseconds
+ };
+ fetchTimer.Elapsed += OnFetchTimer;
}
public async Task FetchDayAsync(DateOnly day) {
@@ -216,15 +227,20 @@ namespace PagerParser.Bart {
}
}
+ private async void OnFetchTimer(object? sender, ElapsedEventArgs e) {
+ await FetchDayAsync(DateOnly.FromDateTime(DateTime.Now));
+ }
+
public async Task StartAsync(CancellationToken cancellationToken) {
logger.LogInformation("BART service starting...");
loginToken = config.GetValue<string>("PagerParser:Bart:Token");
httpClient = new();
- await FetchDayAsync(DateOnly.FromDateTime(DateTime.Now));
+ fetchTimer.Start();
}
public Task StopAsync(CancellationToken cancellationToken) {
logger.LogInformation("BART service stopping...");
+ fetchTimer.Stop();
loginToken = null;
httpClient.Dispose();
return Task.CompletedTask;