This commit is contained in:
2025-06-08 18:14:14 +09:00
parent 2a7ebfe639
commit efa9683cd3
2 changed files with 10 additions and 31 deletions

View File

@ -25,7 +25,7 @@ class BatchScheduler {
constructor() { constructor() {
// Check if initial run is disabled via environment variable // Check if initial run is disabled via environment variable
if (config.batch.disableInitialRun) { 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 // Still schedule regular runs, just skip the initial one
this.scheduleRegularRuns(); this.scheduleRegularRuns();
} else { } else {
@ -72,7 +72,7 @@ class BatchScheduler {
private async runBatch(): Promise<void> { private async runBatch(): Promise<void> {
if (this.state.isRunning) { if (this.state.isRunning) {
console.log("⚠️ Batch process already running, skipping"); console.log("! Batch process already running, skipping");
return; return;
} }
@ -86,27 +86,6 @@ class BatchScheduler {
try { try {
console.log("🔄 Running scheduled batch process..."); 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); await batchProcess(this.currentAbortController.signal);
console.log("✅ Scheduled batch process completed"); console.log("✅ Scheduled batch process completed");
} catch (error) { } catch (error) {
@ -129,7 +108,7 @@ class BatchScheduler {
public enable(): void { public enable(): void {
if (this.state.enabled) { if (this.state.enabled) {
console.log(" Batch scheduler already enabled"); console.log("i Batch scheduler already enabled");
return; return;
} }
@ -140,12 +119,12 @@ class BatchScheduler {
public disable(): void { public disable(): void {
if (!this.state.enabled) { if (!this.state.enabled) {
console.log(" Batch scheduler already disabled"); console.log("i Batch scheduler already disabled");
return; return;
} }
this.state.enabled = false; this.state.enabled = false;
console.log("⏸ Batch scheduler disabled"); console.log("⏸ Batch scheduler disabled");
if (this.state.intervalId) { if (this.state.intervalId) {
clearTimeout(this.state.intervalId); clearTimeout(this.state.intervalId);
@ -164,7 +143,7 @@ class BatchScheduler {
public forceStop(): boolean { public forceStop(): boolean {
if (!this.state.isRunning || !this.currentAbortController) { 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; return false;
} }

View File

@ -107,7 +107,7 @@ function extractDomain(url: string): string | null {
} }
// Initialize database with proper error handling // Initialize database with proper error handling
async function initializeDatabase(): Promise<Database> { function initializeDatabase(): Database {
// Ensure data directory exists // Ensure data directory exists
if (!fs.existsSync(config.paths.dataDir)) { if (!fs.existsSync(config.paths.dataDir)) {
fs.mkdirSync(config.paths.dataDir, { recursive: true }); fs.mkdirSync(config.paths.dataDir, { recursive: true });
@ -205,7 +205,7 @@ async function initializeDatabase(): Promise<Database> {
// Perform database integrity checks and fixes // Perform database integrity checks and fixes
performDatabaseIntegrityFixes(db); performDatabaseIntegrityFixes(db);
await migrateFeedsWithCategories(); migrateFeedsWithCategories(db);
return db; return db;
} }
@ -1126,7 +1126,7 @@ export async function updateFeedRequestStatus(
} }
// Migration function to classify existing feeds without categories // Migration function to classify existing feeds without categories
export async function migrateFeedsWithCategories(): Promise<void> { export function migrateFeedsWithCategories(db: Database): void {
try { try {
console.log("🔄 Starting feed category migration..."); console.log("🔄 Starting feed category migration...");