working #18

Merged
derek merged 19 commits from working into main 2025-08-04 21:16:01 -07:00
2 changed files with 39 additions and 2 deletions
Showing only changes of commit 109306dda2 - Show all commits
+10 -2
View File
@@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt; using System.IdentityModel.Tokens.Jwt;
using System.Security.Cryptography; using System.Security.Cryptography;
using BoredCareers.Services.TimerService;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@@ -35,8 +36,15 @@ string? _dbpass = Environment.GetEnvironmentVariable("MySQLPass");
string dbPass = !string.IsNullOrEmpty(_dbpass) ? _dbpass : "oasv34$8gpv023dd"; string dbPass = !string.IsNullOrEmpty(_dbpass) ? _dbpass : "oasv34$8gpv023dd";
// Create the database serivice // Create the database serivice
DatabaseService databaseService = new DatabaseService(connectionString: "server=" + dbserver + ";user=" + dbUser + ";database=" + dbdatabase + ";password=" + dbPass + ";port=3306;"); builder.Services.AddSingleton<DatabaseService>(sp =>
builder.Services.Add( new ServiceDescriptor( typeof( DatabaseService ), databaseService ) ); new DatabaseService("server=" + dbserver + ";user=" + dbUser + ";database=" + dbdatabase + ";password=" + dbPass + ";port=3306;")
);
////////////////////////////////
/////// Timer Service ///////
////////////////////////////////
builder.Services.AddHostedService<JobCleanupService>();
//////////////////////////////// ////////////////////////////////
///////// Email Service //////// ///////// Email Service ////////
@@ -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);
}
}
}
}