Add in CronJob to update the Financial Data every 2 days
This commit is contained in:
@@ -4,5 +4,6 @@ appdata.db
|
||||
__pycache__
|
||||
obj
|
||||
bin
|
||||
test.db
|
||||
|
||||
!/WebServer/AIPython/python/bin
|
||||
+29
-23
@@ -2,8 +2,6 @@ using WebServer.Components;
|
||||
using PythonInterop;
|
||||
using DataBase;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Load the module in globally and use correct path for local or docker runners
|
||||
#if DEBUG
|
||||
AIModule interopModule = new AIModule(PythonPathBase: "/usr/", PythonVersion: "python3.11");
|
||||
@@ -11,29 +9,37 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
AIModule interopModule = new AIModule();
|
||||
#endif
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
|
||||
if (args.Contains("Pull-Stock-Data")) {
|
||||
interopModule.PullData();
|
||||
} else {
|
||||
// Create the webapp
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Insert the DB driver for Dependency Injection
|
||||
builder.Services.AddSingleton<DbDriver>();
|
||||
// Add services to the container.
|
||||
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
|
||||
|
||||
// Insert the python modlue for Dependency Injection
|
||||
builder.Services.AddSingleton(interopModule);
|
||||
// Insert the DB driver for Dependency Injection
|
||||
builder.Services.AddSingleton<DbDriver>();
|
||||
|
||||
var app = builder.Build();
|
||||
// Insert the python modlue for Dependency Injection
|
||||
builder.Services.AddSingleton(interopModule);
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment()) {
|
||||
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.
|
||||
app.UseHsts();
|
||||
// Build the app
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment()) {
|
||||
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.
|
||||
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();
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
0 0 */2 * * root /app/WebServer Pull-Stock-Data >> /var/log/cron.log 2>&1
|
||||
+16
-1
@@ -37,6 +37,7 @@ RUN apt update && apt upgrade -y && apt install -y \
|
||||
libbz2-dev \
|
||||
wget \
|
||||
ca-certificates \
|
||||
cron \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Download, extract, configure, and compile python 3.11
|
||||
@@ -77,5 +78,19 @@ EXPOSE 5000
|
||||
# Copy in the webserver
|
||||
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
|
||||
ENTRYPOINT ["dotnet", "WebServer.dll", "--url", "http://localhost:5000"]
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user