This commit is contained in:
parent
9ffa8c4cbc
commit
4b4f35b546
6 changed files with 41 additions and 54 deletions
18
Dockerfile
18
Dockerfile
|
@ -8,7 +8,13 @@ COPY . .
|
|||
|
||||
#RUN npm install
|
||||
RUN npm install -g npm@11.2.0
|
||||
RUN npx tsc # TypeScript Code kompilieren
|
||||
RUN npx tsc
|
||||
|
||||
|
||||
### NEW ###
|
||||
RUN npm install -g http-server
|
||||
RUN npx tsc iching/event.ts
|
||||
|
||||
|
||||
# 2. Rust build-Stage
|
||||
FROM forgejo.edf-bootstrap.cx.fg1.ffm.osc.live/devfw-cicd/rust:1.74.0 AS rust-build
|
||||
|
@ -24,7 +30,11 @@ COPY --from=build /app .
|
|||
COPY --from=rust-build /usr/local/cargo/bin/iching /usr/local/bin/iching
|
||||
|
||||
# 5. Run app
|
||||
CMD ["npx", "ts-node", "broker.ts"]
|
||||
#CMD ["npx", "ts-node", "broker.ts"]
|
||||
|
||||
#run indefinitely to avoid CrashLoopBackOff
|
||||
#CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait"
|
||||
### NEW ###
|
||||
#RUN npx ts-node event.ts
|
||||
|
||||
|
||||
#CMD ["http-server", "."]
|
||||
CMD ["npx", "http-server", "-p", "1234"]
|
||||
|
|
|
@ -3,8 +3,6 @@ import * as fs from 'fs';
|
|||
|
||||
// Config for scheduling the next time the main process (sending of horoscope) is run
|
||||
interface Config {
|
||||
daysInterval: number;
|
||||
timeOfDay: string;
|
||||
emailReceiver: string;
|
||||
mailHost: string;
|
||||
mailPort: number;
|
||||
|
@ -21,7 +19,7 @@ var config : Config;
|
|||
|
||||
const nodemailer = require('nodemailer');
|
||||
|
||||
function executeCommand(): void {
|
||||
export function executeCommand(): void {
|
||||
|
||||
exec('iching divine', (error, stdout, stderr) => {
|
||||
|
||||
|
@ -44,13 +42,6 @@ function executeCommand(): void {
|
|||
|
||||
console.log(`Send E-Mail`);
|
||||
sendEmail(stdout);
|
||||
|
||||
// Calculate next execution time
|
||||
const nextRunDate = calculateNextRunDate(config.daysInterval, config.timeOfDay);
|
||||
console.log(`Next execution: ${nextRunDate}`);
|
||||
|
||||
// Start Scheduling
|
||||
scheduleNextRun(nextRunDate);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -91,44 +82,6 @@ async function sendEmail(content: string) {
|
|||
}
|
||||
}
|
||||
|
||||
//Calculate the time for the next execution of the main process, depending on configuration.
|
||||
//Returns the time of the next process loop.
|
||||
function calculateNextRunDate(daysInterval: number, timeOfDay: string): Date {
|
||||
const currentDate = new Date();
|
||||
|
||||
// Splitte die Uhrzeit in Stunden und Minuten
|
||||
const [hours, minutes] = timeOfDay.split(':').map(Number);
|
||||
|
||||
// Berechne das Datum für die nächste Ausführung
|
||||
currentDate.setHours(hours, minutes, 0, 0); // Setze die Uhrzeit auf Y (z.B. 14:30)
|
||||
|
||||
// Wenn die Uhrzeit bereits vorbei ist, verschiebe das Datum auf den nächsten Tag
|
||||
if (currentDate < new Date()) {
|
||||
currentDate.setDate(currentDate.getDate() + 1); // Setze auf den nächsten Tag
|
||||
}
|
||||
|
||||
// Berechne das Datum für den nächsten Ausführungszeitpunkt unter Berücksichtigung von X Tagen
|
||||
currentDate.setDate(currentDate.getDate() + daysInterval);
|
||||
|
||||
return currentDate;
|
||||
}
|
||||
|
||||
//Schedule the next process loop.
|
||||
function scheduleNextRun(nextRunDate: Date) {
|
||||
const now = new Date();
|
||||
const timeUntilNextRun = nextRunDate.getTime() - now.getTime();
|
||||
|
||||
if (timeUntilNextRun > 0) {
|
||||
setTimeout(() => {
|
||||
console.log('Next iteration of Process was scheduled!');
|
||||
|
||||
//run the main process
|
||||
executeCommand();
|
||||
|
||||
}, timeUntilNextRun);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate 1) Parse Tree and 2) HTML
|
||||
export function html(inputText: string): string {
|
||||
const parseTree = parse(inputText);
|
|
@ -1,6 +1,4 @@
|
|||
{
|
||||
"daysInterval": 7,
|
||||
"timeOfDay": "8:00",
|
||||
"emailReceiver": "test@mailhog.local",
|
||||
"mailHost": "mailhog.mailhog.svc.cluster.local",
|
||||
"mailPort": 1025
|
13
iching/event.ts
Normal file
13
iching/event.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { executeCommand } from './broker';
|
||||
|
||||
function handleClick(): void {
|
||||
console.log("Der Button wurde geklickt!");
|
||||
alert("Hallo von TypeScript!");
|
||||
|
||||
executeCommand();
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const button = document.getElementById("myButton");
|
||||
button?.addEventListener("click", handleClick);
|
||||
});
|
13
iching/index.html
Normal file
13
iching/index.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Button mit TypeScript</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Mein Button</h1>
|
||||
<button id="myButton">Klick mich!</button>
|
||||
|
||||
<script src="event.js"></script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue