Start Job Cleanup Service

This commit is contained in:
2025-08-04 16:27:25 -07:00
parent bdc5b346a8
commit 109306dda2
2 changed files with 39 additions and 2 deletions
@@ -0,0 +1,29 @@
using BoredCareers.Entities;
namespace BoredCareers.Services.TimerService {
public class JobCleanupService : BackgroundService {
private readonly DatabaseService.DatabaseService _db;
public JobCleanupService(DatabaseService.DatabaseService db) {
_db = db;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
while (!stoppingToken.IsCancellationRequested) {
try {
JobListing[] deletedJobListings = await _db.GetJobListingsPastExipre();
await _db.DeleteJobListingsPastExipre();
foreach (JobListing listing in deletedJobListings) {
// Get applicants for each closed listing
// Notify applicants of the listing closing
// Mark company for auto-closed job -> ghost listing
}
} catch (Exception e) {
Console.WriteLine($"Error: {e.Message}");
}
await Task.Delay(TimeSpan.FromHours(24), stoppingToken);
}
}
}
}