Update
This commit is contained in:
		@@ -25,7 +25,7 @@ class BatchScheduler {
 | 
			
		||||
  constructor() {
 | 
			
		||||
    // Check if initial run is disabled via environment variable
 | 
			
		||||
    if (config.batch.disableInitialRun) {
 | 
			
		||||
      console.log("⏸️  Initial batch run disabled by configuration");
 | 
			
		||||
      console.log("⏸  Initial batch run disabled by configuration");
 | 
			
		||||
      // Still schedule regular runs, just skip the initial one
 | 
			
		||||
      this.scheduleRegularRuns();
 | 
			
		||||
    } else {
 | 
			
		||||
@@ -72,7 +72,7 @@ class BatchScheduler {
 | 
			
		||||
 | 
			
		||||
  private async runBatch(): Promise<void> {
 | 
			
		||||
    if (this.state.isRunning) {
 | 
			
		||||
      console.log("⚠️  Batch process already running, skipping");
 | 
			
		||||
      console.log("!  Batch process already running, skipping");
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -86,27 +86,6 @@ class BatchScheduler {
 | 
			
		||||
    try {
 | 
			
		||||
      console.log("🔄 Running scheduled batch process...");
 | 
			
		||||
 | 
			
		||||
      // Run migration for feeds without categories (only once)
 | 
			
		||||
      if (!this.migrationCompleted) {
 | 
			
		||||
        try {
 | 
			
		||||
          const { migrateFeedsWithCategories, getFeedCategoryMigrationStatus } = await import("./database.js");
 | 
			
		||||
          const migrationStatus = await getFeedCategoryMigrationStatus();
 | 
			
		||||
          
 | 
			
		||||
          if (!migrationStatus.migrationComplete) {
 | 
			
		||||
            console.log("🔄 Running feed category migration...");
 | 
			
		||||
            await migrateFeedsWithCategories();
 | 
			
		||||
            this.migrationCompleted = true;
 | 
			
		||||
          } else {
 | 
			
		||||
            console.log("✅ Feed category migration already complete");
 | 
			
		||||
            this.migrationCompleted = true;
 | 
			
		||||
          }
 | 
			
		||||
        } catch (migrationError) {
 | 
			
		||||
          console.error("❌ Error during feed category migration:", migrationError);
 | 
			
		||||
          // Don't fail the entire batch process due to migration error
 | 
			
		||||
          this.migrationCompleted = true; // Mark as completed to avoid retrying every batch
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      await batchProcess(this.currentAbortController.signal);
 | 
			
		||||
      console.log("✅ Scheduled batch process completed");
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
@@ -129,7 +108,7 @@ class BatchScheduler {
 | 
			
		||||
 | 
			
		||||
  public enable(): void {
 | 
			
		||||
    if (this.state.enabled) {
 | 
			
		||||
      console.log("ℹ️  Batch scheduler already enabled");
 | 
			
		||||
      console.log("i  Batch scheduler already enabled");
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -140,12 +119,12 @@ class BatchScheduler {
 | 
			
		||||
 | 
			
		||||
  public disable(): void {
 | 
			
		||||
    if (!this.state.enabled) {
 | 
			
		||||
      console.log("ℹ️  Batch scheduler already disabled");
 | 
			
		||||
      console.log("i  Batch scheduler already disabled");
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    this.state.enabled = false;
 | 
			
		||||
    console.log("⏸️  Batch scheduler disabled");
 | 
			
		||||
    console.log("⏸  Batch scheduler disabled");
 | 
			
		||||
 | 
			
		||||
    if (this.state.intervalId) {
 | 
			
		||||
      clearTimeout(this.state.intervalId);
 | 
			
		||||
@@ -164,7 +143,7 @@ class BatchScheduler {
 | 
			
		||||
 | 
			
		||||
  public forceStop(): boolean {
 | 
			
		||||
    if (!this.state.isRunning || !this.currentAbortController) {
 | 
			
		||||
      console.log("ℹ️  No batch process currently running to stop");
 | 
			
		||||
      console.log("i  No batch process currently running to stop");
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -107,7 +107,7 @@ function extractDomain(url: string): string | null {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Initialize database with proper error handling
 | 
			
		||||
async function initializeDatabase(): Promise<Database> {
 | 
			
		||||
function initializeDatabase(): Database {
 | 
			
		||||
  // Ensure data directory exists
 | 
			
		||||
  if (!fs.existsSync(config.paths.dataDir)) {
 | 
			
		||||
    fs.mkdirSync(config.paths.dataDir, { recursive: true });
 | 
			
		||||
@@ -205,7 +205,7 @@ async function initializeDatabase(): Promise<Database> {
 | 
			
		||||
  // Perform database integrity checks and fixes
 | 
			
		||||
  performDatabaseIntegrityFixes(db);
 | 
			
		||||
 | 
			
		||||
  await migrateFeedsWithCategories();
 | 
			
		||||
  migrateFeedsWithCategories(db);
 | 
			
		||||
 | 
			
		||||
  return db;
 | 
			
		||||
}
 | 
			
		||||
@@ -1126,7 +1126,7 @@ export async function updateFeedRequestStatus(
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Migration function to classify existing feeds without categories
 | 
			
		||||
export async function migrateFeedsWithCategories(): Promise<void> {
 | 
			
		||||
export function migrateFeedsWithCategories(db: Database): void {
 | 
			
		||||
  try {
 | 
			
		||||
    console.log("🔄 Starting feed category migration...");
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user