start
This commit is contained in:
@@ -24,8 +24,11 @@ public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Console.println("=== Troostwijk Auction Monitor ===\n");
|
||||
|
||||
// Configuration
|
||||
String databaseFile = System.getenv().getOrDefault("DATABASE_FILE", "troostwijk.db");
|
||||
// Parse command line arguments
|
||||
String mode = args.length > 0 ? args[0] : "workflow";
|
||||
|
||||
// Configuration - Windows paths
|
||||
String databaseFile = System.getenv().getOrDefault("DATABASE_FILE", "C:\\mnt\\okcomputer\\output\\cache.db");
|
||||
String notificationConfig = System.getenv().getOrDefault("NOTIFICATION_CONFIG", "desktop");
|
||||
|
||||
// YOLO model paths (optional - monitor works without object detection)
|
||||
@@ -41,19 +44,109 @@ public class Main {
|
||||
Console.println("⚠️ OpenCV not available - image detection disabled");
|
||||
}
|
||||
|
||||
Console.println("Initializing monitor...");
|
||||
var monitor = new TroostwijkMonitor(databaseFile, notificationConfig,
|
||||
switch (mode.toLowerCase()) {
|
||||
case "workflow":
|
||||
runWorkflowMode(databaseFile, notificationConfig, yoloCfg, yoloWeights, yoloClasses);
|
||||
break;
|
||||
|
||||
case "once":
|
||||
runOnceMode(databaseFile, notificationConfig, yoloCfg, yoloWeights, yoloClasses);
|
||||
break;
|
||||
|
||||
case "legacy":
|
||||
runLegacyMode(databaseFile, notificationConfig, yoloCfg, yoloWeights, yoloClasses);
|
||||
break;
|
||||
|
||||
case "status":
|
||||
showStatus(databaseFile, notificationConfig, yoloCfg, yoloWeights, yoloClasses);
|
||||
break;
|
||||
|
||||
default:
|
||||
showUsage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* WORKFLOW MODE: Run orchestrated scheduled workflows (default)
|
||||
* This is the recommended mode for production use.
|
||||
*/
|
||||
private static void runWorkflowMode(String dbPath, String notifConfig,
|
||||
String yoloCfg, String yoloWeights, String yoloClasses)
|
||||
throws Exception {
|
||||
|
||||
Console.println("🚀 Starting in WORKFLOW MODE (Orchestrated Scheduling)\n");
|
||||
|
||||
WorkflowOrchestrator orchestrator = new WorkflowOrchestrator(
|
||||
dbPath, notifConfig, yoloCfg, yoloWeights, yoloClasses
|
||||
);
|
||||
|
||||
// Show initial status
|
||||
orchestrator.printStatus();
|
||||
|
||||
// Start all scheduled workflows
|
||||
orchestrator.startScheduledWorkflows();
|
||||
|
||||
Console.println("✓ All workflows are running");
|
||||
Console.println(" - Scraper import: every 30 min");
|
||||
Console.println(" - Image processing: every 1 hour");
|
||||
Console.println(" - Bid monitoring: every 15 min");
|
||||
Console.println(" - Closing alerts: every 5 min");
|
||||
Console.println("\nPress Ctrl+C to stop.\n");
|
||||
|
||||
// Add shutdown hook
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
Console.println("\n🛑 Shutdown signal received...");
|
||||
orchestrator.shutdown();
|
||||
}));
|
||||
|
||||
// Keep application alive
|
||||
try {
|
||||
Thread.sleep(Long.MAX_VALUE);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
orchestrator.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ONCE MODE: Run complete workflow once and exit
|
||||
* Useful for cron jobs or scheduled tasks.
|
||||
*/
|
||||
private static void runOnceMode(String dbPath, String notifConfig,
|
||||
String yoloCfg, String yoloWeights, String yoloClasses)
|
||||
throws Exception {
|
||||
|
||||
Console.println("🔄 Starting in ONCE MODE (Single Execution)\n");
|
||||
|
||||
WorkflowOrchestrator orchestrator = new WorkflowOrchestrator(
|
||||
dbPath, notifConfig, yoloCfg, yoloWeights, yoloClasses
|
||||
);
|
||||
|
||||
orchestrator.runCompleteWorkflowOnce();
|
||||
|
||||
Console.println("✓ Workflow execution completed. Exiting.\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* LEGACY MODE: Original monitoring approach
|
||||
* Kept for backward compatibility.
|
||||
*/
|
||||
private static void runLegacyMode(String dbPath, String notifConfig,
|
||||
String yoloCfg, String yoloWeights, String yoloClasses)
|
||||
throws Exception {
|
||||
|
||||
Console.println("⚙️ Starting in LEGACY MODE\n");
|
||||
|
||||
var monitor = new TroostwijkMonitor(dbPath, notifConfig,
|
||||
yoloCfg, yoloWeights, yoloClasses);
|
||||
|
||||
// Show current database state
|
||||
Console.println("\n📊 Current Database State:");
|
||||
monitor.printDatabaseStats();
|
||||
|
||||
// Check for pending image processing
|
||||
Console.println("\n[1/2] Processing images...");
|
||||
monitor.processPendingImages();
|
||||
|
||||
// Start monitoring service
|
||||
Console.println("\n[2/2] Starting bid monitoring...");
|
||||
monitor.scheduleMonitoring();
|
||||
|
||||
@@ -61,7 +154,6 @@ public class Main {
|
||||
Console.println("NOTE: This process expects auction/lot data from the external scraper.");
|
||||
Console.println(" Make sure ARCHITECTURE-TROOSTWIJK-SCRAPER is running and populating the database.\n");
|
||||
|
||||
// Keep application alive
|
||||
try {
|
||||
Thread.sleep(Long.MAX_VALUE);
|
||||
} catch (InterruptedException e) {
|
||||
@@ -70,6 +162,44 @@ public class Main {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* STATUS MODE: Show current status and exit
|
||||
*/
|
||||
private static void showStatus(String dbPath, String notifConfig,
|
||||
String yoloCfg, String yoloWeights, String yoloClasses)
|
||||
throws Exception {
|
||||
|
||||
Console.println("📊 Checking Status...\n");
|
||||
|
||||
WorkflowOrchestrator orchestrator = new WorkflowOrchestrator(
|
||||
dbPath, notifConfig, yoloCfg, yoloWeights, yoloClasses
|
||||
);
|
||||
|
||||
orchestrator.printStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show usage information
|
||||
*/
|
||||
private static void showUsage() {
|
||||
Console.println("Usage: java -jar troostwijk-monitor.jar [mode]\n");
|
||||
Console.println("Modes:");
|
||||
Console.println(" workflow - Run orchestrated scheduled workflows (default)");
|
||||
Console.println(" once - Run complete workflow once and exit (for cron)");
|
||||
Console.println(" legacy - Run original monitoring approach");
|
||||
Console.println(" status - Show current status and exit");
|
||||
Console.println("\nEnvironment Variables:");
|
||||
Console.println(" DATABASE_FILE - Path to SQLite database");
|
||||
Console.println(" (default: C:\\mnt\\okcomputer\\output\\cache.db)");
|
||||
Console.println(" NOTIFICATION_CONFIG - 'desktop' or 'smtp:user:pass:email'");
|
||||
Console.println(" (default: desktop)");
|
||||
Console.println("\nExamples:");
|
||||
Console.println(" java -jar troostwijk-monitor.jar workflow");
|
||||
Console.println(" java -jar troostwijk-monitor.jar once");
|
||||
Console.println(" java -jar troostwijk-monitor.jar status");
|
||||
Console.println();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative entry point for container environments.
|
||||
* Simply keeps the container alive for manual commands.
|
||||
|
||||
Reference in New Issue
Block a user