Refactor logging in cleanup scripts to use report array for improved output management
Updated various cleanup scripts to replace console.log statements with a report array, enhancing the output handling and allowing for better formatting of messages. This change improves the readability of logs and ensures consistent reporting across different cleanup operations, including database connection status, index management, and summary reports.
This commit is contained in:
@@ -277,12 +277,6 @@ class DiaryDateActivityService {
|
||||
throw new Error('Group not found');
|
||||
}
|
||||
|
||||
console.log('[DiaryDateActivityService::addGroupActivity] Group found:', {
|
||||
groupId: group.id,
|
||||
groupDiaryDateId: group.diaryDateId,
|
||||
activityDiaryDateId: diaryDateActivity.diaryDateId
|
||||
});
|
||||
|
||||
if (group.diaryDateId !== diaryDateActivity.diaryDateId) {
|
||||
console.error('[DiaryDateActivityService::addGroupActivity] Group and date don\'t fit');
|
||||
console.error('Group diaryDateId:', group.diaryDateId, 'Activity diaryDateId:', diaryDateActivity.diaryDateId);
|
||||
|
||||
@@ -230,7 +230,6 @@ class MemberService {
|
||||
try {
|
||||
session = await myTischtennisService.getSession(userId);
|
||||
} catch (sessionError) {
|
||||
console.log('[updateRatingsFromMyTischtennis] - Session invalid, attempting login...', sessionError.message);
|
||||
|
||||
// Versuche automatischen Login mit gespeicherten Credentials
|
||||
try {
|
||||
@@ -243,7 +242,6 @@ class MemberService {
|
||||
expiresAt: freshSession.expiresAt,
|
||||
userData: freshSession.userData
|
||||
};
|
||||
console.log('[updateRatingsFromMyTischtennis] - Automatic login successful');
|
||||
} catch (loginError) {
|
||||
console.error('[updateRatingsFromMyTischtennis] - Automatic login failed:', loginError.message);
|
||||
return {
|
||||
@@ -354,6 +352,7 @@ class MemberService {
|
||||
account.fedNickname,
|
||||
'no'
|
||||
);
|
||||
let qttrWarning = null;
|
||||
try {
|
||||
await (await import('./apiLogService.js')).default.logRequest({
|
||||
userId,
|
||||
@@ -386,7 +385,7 @@ class MemberService {
|
||||
}
|
||||
if (!rankingsQuarter.success) {
|
||||
// QTTR optional; nicht hart abbrechen, aber vermerken
|
||||
console.warn('[updateRatingsFromMyTischtennis] - QTTR Abruf fehlgeschlagen:', rankingsQuarter.error);
|
||||
qttrWarning = rankingsQuarter.error || 'QTTR Abruf fehlgeschlagen';
|
||||
}
|
||||
|
||||
// 3. Alle Mitglieder des Clubs laden
|
||||
@@ -394,6 +393,12 @@ class MemberService {
|
||||
|
||||
let updated = 0;
|
||||
const errors = [];
|
||||
if (qttrWarning) {
|
||||
errors.push({
|
||||
type: 'warning',
|
||||
message: qttrWarning
|
||||
});
|
||||
}
|
||||
const notFound = [];
|
||||
const matched = [];
|
||||
|
||||
|
||||
@@ -109,21 +109,11 @@ class PDFParserService {
|
||||
const result = strategy.fn(lines, clubId, filteredLineEntries.length === lines.length ? filteredLineEntries : null);
|
||||
|
||||
if (result.matches.length > 0) {
|
||||
console.log(`[PDF Parser] Using strategy: ${strategy.name}, found ${result.matches.length} matches`);
|
||||
if (result.matches.length > 0) {
|
||||
console.log(`[PDF Parser] First match sample:`, {
|
||||
homeTeamName: result.matches[0].homeTeamName,
|
||||
guestTeamName: result.matches[0].guestTeamName,
|
||||
date: result.matches[0].date,
|
||||
rawLine: result.matches[0].rawLine
|
||||
});
|
||||
}
|
||||
matches.push(...result.matches);
|
||||
metadata.parsedMatches += result.matches.length;
|
||||
break; // Erste erfolgreiche Strategie verwenden
|
||||
}
|
||||
} catch (strategyError) {
|
||||
console.log(`[PDF Parser] Strategy ${strategy.name} failed:`, strategyError.message);
|
||||
errors.push(`Strategy ${strategy.name} failed: ${strategyError.message}`);
|
||||
}
|
||||
}
|
||||
@@ -423,18 +413,6 @@ class PDFParserService {
|
||||
}
|
||||
|
||||
if (homeTeamName && guestTeamName) {
|
||||
let debugInfo;
|
||||
if (code) {
|
||||
debugInfo = `code: "${code}"`;
|
||||
} else if (homePin && guestPin) {
|
||||
debugInfo = `homePin: "${homePin}", guestPin: "${guestPin}"`;
|
||||
} else if (homePin) {
|
||||
debugInfo = `homePin: "${homePin}"`;
|
||||
} else if (guestPin) {
|
||||
debugInfo = `guestPin: "${guestPin}"`;
|
||||
}
|
||||
|
||||
console.log(`[PDF Parser] Parsed match: ${homeTeamName} vs ${guestTeamName}, ${debugInfo}`);
|
||||
|
||||
matches.push({
|
||||
date: date,
|
||||
@@ -769,27 +747,18 @@ class PDFParserService {
|
||||
where: { clubId: matchData.clubId },
|
||||
attributes: ['id', 'name']
|
||||
});
|
||||
console.log(`[PDF Parser] Available teams in club: ${allTeams.map(t => t.name).join(', ')}`);
|
||||
|
||||
// Fuzzy-Matching für Team-Namen
|
||||
if (!homeTeam) {
|
||||
homeTeam = allTeams.find(t =>
|
||||
PDFParserService.namesRoughlyMatch(t.name, matchData.homeTeamName)
|
||||
);
|
||||
|
||||
if (homeTeam) {
|
||||
console.log(`[PDF Parser] Found home team via fuzzy match: "${matchData.homeTeamName}" → "${homeTeam.name}"`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!guestTeam) {
|
||||
guestTeam = allTeams.find(t =>
|
||||
PDFParserService.namesRoughlyMatch(t.name, matchData.guestTeamName)
|
||||
);
|
||||
|
||||
if (guestTeam) {
|
||||
console.log(`[PDF Parser] Found guest team via fuzzy match: "${matchData.guestTeamName}" → "${guestTeam.name}"`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,28 +24,22 @@ class SchedulerService {
|
||||
// Schedule automatic rating updates at 6:00 AM daily
|
||||
const ratingUpdateJob = cron.schedule('0 6 * * *', async () => {
|
||||
const startTime = Date.now();
|
||||
const timestamp = new Date().toISOString();
|
||||
console.log(`[${timestamp}] CRON: Executing scheduled rating updates...`);
|
||||
devLog('Executing scheduled rating updates...');
|
||||
devLog(`[${new Date().toISOString()}] CRON: Executing scheduled rating updates...`);
|
||||
|
||||
let success = false;
|
||||
let message = '';
|
||||
let errorMessage = null;
|
||||
|
||||
try {
|
||||
// Let the service return details including counts if available
|
||||
const result = await autoUpdateRatingsService.executeAutomaticUpdates();
|
||||
const executionTime = Date.now() - startTime;
|
||||
success = true;
|
||||
// result may include updatedCount or a summary object
|
||||
const messageObj = result && typeof result === 'object' ? result : { message: 'Rating updates completed successfully' };
|
||||
console.log(`[${new Date().toISOString()}] CRON: Rating updates completed successfully`);
|
||||
|
||||
// Log to ApiLog with rich details
|
||||
await apiLogService.logSchedulerExecution('rating_updates', true, messageObj, executionTime, null);
|
||||
devLog('Scheduled rating updates completed successfully');
|
||||
} catch (error) {
|
||||
const executionTime = Date.now() - startTime;
|
||||
success = false;
|
||||
errorMessage = error.message;
|
||||
console.error(`[${new Date().toISOString()}] CRON ERROR in scheduled rating updates:`, error);
|
||||
console.error('Stack trace:', error.stack);
|
||||
@@ -60,32 +54,26 @@ class SchedulerService {
|
||||
|
||||
this.jobs.set('ratingUpdates', ratingUpdateJob);
|
||||
ratingUpdateJob.start();
|
||||
console.log('[Scheduler] Rating update job scheduled and started');
|
||||
devLog('Rating update job scheduled and started');
|
||||
|
||||
// Schedule automatic match results fetching at 6:30 AM daily
|
||||
const matchResultsJob = cron.schedule('30 6 * * *', async () => {
|
||||
const startTime = Date.now();
|
||||
const timestamp = new Date().toISOString();
|
||||
console.log(`[${timestamp}] CRON: Executing scheduled match results fetch...`);
|
||||
devLog('Executing scheduled match results fetch...');
|
||||
devLog(`[${new Date().toISOString()}] CRON: Executing scheduled match results fetch...`);
|
||||
|
||||
let success = false;
|
||||
let message = '';
|
||||
let errorMessage = null;
|
||||
|
||||
try {
|
||||
// Execute and capture returned summary (should include counts)
|
||||
const result = await autoFetchMatchResultsService.executeAutomaticFetch();
|
||||
const executionTime = Date.now() - startTime;
|
||||
success = true;
|
||||
const messageObj = result && typeof result === 'object' ? result : { message: 'Match results fetch completed successfully' };
|
||||
console.log(`[${new Date().toISOString()}] CRON: Match results fetch completed successfully`);
|
||||
|
||||
// Log to ApiLog with rich details (including counts if present)
|
||||
await apiLogService.logSchedulerExecution('match_results', true, messageObj, executionTime, null);
|
||||
devLog('Scheduled match results fetch completed successfully');
|
||||
} catch (error) {
|
||||
const executionTime = Date.now() - startTime;
|
||||
success = false;
|
||||
errorMessage = error.message;
|
||||
console.error(`[${new Date().toISOString()}] CRON ERROR in scheduled match results fetch:`, error);
|
||||
console.error('Stack trace:', error.stack);
|
||||
@@ -100,7 +88,7 @@ class SchedulerService {
|
||||
|
||||
this.jobs.set('matchResults', matchResultsJob);
|
||||
matchResultsJob.start();
|
||||
console.log('[Scheduler] Match results fetch job scheduled and started');
|
||||
devLog('Match results fetch job scheduled and started');
|
||||
|
||||
this.isRunning = true;
|
||||
const now = new Date();
|
||||
@@ -112,12 +100,12 @@ class SchedulerService {
|
||||
tomorrow630AM.setDate(tomorrow630AM.getDate() + 1);
|
||||
tomorrow630AM.setHours(6, 30, 0, 0);
|
||||
|
||||
console.log('[Scheduler] ===== SCHEDULER SERVICE STARTED =====');
|
||||
console.log(`[Scheduler] Server time: ${now.toISOString()}`);
|
||||
console.log(`[Scheduler] Timezone: Europe/Berlin`);
|
||||
console.log(`[Scheduler] Rating updates: Next execution at ${tomorrow6AM.toISOString()} (6:00 AM Berlin time)`);
|
||||
console.log(`[Scheduler] Match results fetch: Next execution at ${tomorrow630AM.toISOString()} (6:30 AM Berlin time)`);
|
||||
console.log('[Scheduler] =====================================');
|
||||
devLog('[Scheduler] ===== SCHEDULER SERVICE STARTED =====');
|
||||
devLog(`[Scheduler] Server time: ${now.toISOString()}`);
|
||||
devLog(`[Scheduler] Timezone: Europe/Berlin`);
|
||||
devLog(`[Scheduler] Rating updates: Next execution at ${tomorrow6AM.toISOString()} (6:00 AM Berlin time)`);
|
||||
devLog(`[Scheduler] Match results fetch: Next execution at ${tomorrow630AM.toISOString()} (6:30 AM Berlin time)`);
|
||||
devLog('[Scheduler] =====================================');
|
||||
|
||||
devLog('Scheduler service started successfully');
|
||||
devLog('Rating updates scheduled for 6:00 AM daily (Europe/Berlin timezone)');
|
||||
|
||||
@@ -207,7 +207,6 @@ class TournamentService {
|
||||
const gm = await TournamentMember.findAll({ where: { groupId: g.id } });
|
||||
|
||||
if (gm.length < 2) {
|
||||
console.warn(`Gruppe ${g.id} hat nur ${gm.length} Teilnehmer - keine Matches erstellt`);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -227,8 +226,6 @@ class TournamentService {
|
||||
player2Id: p2Id,
|
||||
groupRound: roundIndex + 1
|
||||
});
|
||||
} else {
|
||||
console.warn(`Spieler gehören nicht zur gleichen Gruppe: ${p1Id} (${p1?.groupId}) vs ${p2Id} (${p2?.groupId}) in Gruppe ${g.id}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user