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
+26 -20
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,29 +9,37 @@ var builder = WebApplication.CreateBuilder(args);
AIModule interopModule = new AIModule(); AIModule interopModule = new AIModule();
#endif #endif
// Add services to the container. if (args.Contains("Pull-Stock-Data")) {
builder.Services.AddRazorComponents().AddInteractiveServerComponents(); interopModule.PullData();
} else {
// Create the webapp
var builder = WebApplication.CreateBuilder(args);
// Insert the DB driver for Dependency Injection // Add services to the container.
builder.Services.AddSingleton<DbDriver>(); builder.Services.AddRazorComponents().AddInteractiveServerComponents();
// Insert the python modlue for Dependency Injection // Insert the DB driver for Dependency Injection
builder.Services.AddSingleton(interopModule); builder.Services.AddSingleton<DbDriver>();
var app = builder.Build(); // Insert the python modlue for Dependency Injection
builder.Services.AddSingleton(interopModule);
// Configure the HTTP request pipeline. // Build the app
if (!app.Environment.IsDevelopment()) { var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment()) {
app.UseExceptionHandler("/Error", createScopeForErrors: true); app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts(); app.UseHsts();
}
// Conffigure policies
app.UseHttpsRedirection();
app.UseAntiforgery();
app.MapStaticAssets();
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();
// Start the web app
app.Run();
} }
app.UseHttpsRedirection();
app.UseAntiforgery();
app.MapStaticAssets();
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();
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