Add in CronJob to update the Financial Data every 2 days

This commit is contained in:
2026-02-16 16:37:35 -08:00
parent 56760f9dff
commit 37687b64c7
5 changed files with 52 additions and 22 deletions
+1
View File
@@ -4,5 +4,6 @@ appdata.db
__pycache__ __pycache__
obj obj
bin bin
test.db
!/WebServer/AIPython/python/bin !/WebServer/AIPython/python/bin
+10 -4
View File
@@ -2,8 +2,6 @@ using WebServer.Components;
using PythonInterop; using PythonInterop;
using DataBase; using DataBase;
var builder = WebApplication.CreateBuilder(args);
// Load the module in globally and use correct path for local or docker runners // Load the module in globally and use correct path for local or docker runners
#if DEBUG #if DEBUG
AIModule interopModule = new AIModule(PythonPathBase: "/usr/", PythonVersion: "python3.11"); AIModule interopModule = new AIModule(PythonPathBase: "/usr/", PythonVersion: "python3.11");
@@ -11,6 +9,12 @@ var builder = WebApplication.CreateBuilder(args);
AIModule interopModule = new AIModule(); AIModule interopModule = new AIModule();
#endif #endif
if (args.Contains("Pull-Stock-Data")) {
interopModule.PullData();
} else {
// Create the webapp
var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddRazorComponents().AddInteractiveServerComponents(); builder.Services.AddRazorComponents().AddInteractiveServerComponents();
@@ -20,6 +24,7 @@ builder.Services.AddSingleton<DbDriver>();
// Insert the python modlue for Dependency Injection // Insert the python modlue for Dependency Injection
builder.Services.AddSingleton(interopModule); builder.Services.AddSingleton(interopModule);
// Build the app
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
@@ -29,11 +34,12 @@ if (!app.Environment.IsDevelopment()) {
app.UseHsts(); app.UseHsts();
} }
// Conffigure policies
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseAntiforgery(); app.UseAntiforgery();
app.MapStaticAssets(); app.MapStaticAssets();
app.MapRazorComponents<App>().AddInteractiveServerRenderMode(); app.MapRazorComponents<App>().AddInteractiveServerRenderMode();
// Start the web app
app.Run(); app.Run();
}
+1
View File
@@ -0,0 +1 @@
0 0 */2 * * root /app/WebServer Pull-Stock-Data >> /var/log/cron.log 2>&1
+16 -1
View File
@@ -37,6 +37,7 @@ RUN apt update && apt upgrade -y && apt install -y \
libbz2-dev \ libbz2-dev \
wget \ wget \
ca-certificates \ ca-certificates \
cron \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Download, extract, configure, and compile python 3.11 # Download, extract, configure, and compile python 3.11
@@ -77,5 +78,19 @@ EXPOSE 5000
# Copy in the webserver # Copy in the webserver
COPY --from=build-Webserver /app/publish ./ COPY --from=build-Webserver /app/publish ./
# Copy in cronjob
COPY crontab.txt /etc/cron.d/reload-finance-history
# Copy in EntryPoint
COPY entrypoint.sh /entrypoint.sh
# Give execution rights on the cronjob and entrypoint
RUN chmod 0644 /etc/cron.d/reload-finance-history && \
chmod +x /entrypoint.sh && \
touch /var/log/cron.log
# Apply the cron job
RUN crontab /etc/cron.d/reload-finance-history
# Start the container # Start the container
ENTRYPOINT ["dotnet", "WebServer.dll", "--url", "http://localhost:5000"] ENTRYPOINT ["/entrypoint.sh"]
+7
View File
@@ -0,0 +1,7 @@
#!/bin/bash
# Start the cron daemon in the background
service cron start
# Run your main application (this keeps the container alive)
exec /app/WebServer