Skip to content

Commit

Permalink
feat: ignore network error to error log (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Oct 26, 2023
1 parent 3cdb7cc commit 22d401e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
14 changes: 12 additions & 2 deletions app/core/service/BinarySyncerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ export class BinarySyncerService extends AbstractService {
logs.push(`[${isoNow()}] ❌❌❌❌❌ "${binaryName}" ❌❌❌❌❌`);
this.logger.error('[BinarySyncerService.executeTask:fail] taskId: %s, targetName: %s, %s',
task.taskId, task.targetName, task.error);
this.logger.error(err);
if (err.name === 'HttpClientRequestTimeoutError'
|| err.name === 'ConnectionError'
|| err.name === 'ConnectTimeoutError') {
this.logger.warn(err);
} else {
this.logger.error(err);
}
await this.taskService.finishTask(task, TaskState.Fail, logs.join('\n'));
}
}
Expand Down Expand Up @@ -210,7 +216,11 @@ export class BinarySyncerService extends AbstractService {
this.logger.info('Not found %s, skip it', item.sourceUrl);
logs.push(`[${isoNow()}][${dir}] 🧪️ [${parentIndex}${index}] Download ${item.sourceUrl} not found, skip it`);
} else {
this.logger.error('Download binary %s %s', item.sourceUrl, err);
if (err.name === 'DownloadStatusInvalidError') {
this.logger.warn('Download binary %s %s', item.sourceUrl, err);
} else {
this.logger.error('Download binary %s %s', item.sourceUrl, err);
}
hasDownloadError = true;
logs.push(`[${isoNow()}][${dir}] ❌ [${parentIndex}${index}] Download ${item.sourceUrl} error: ${err}`);
}
Expand Down
6 changes: 5 additions & 1 deletion app/core/service/PackageSyncerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,11 @@ export class PackageSyncerService extends AbstractService {
localFile = tmpfile;
logs.push(`[${isoNow()}] 🚧 [${syncIndex}] HTTP content-length: ${headers['content-length']}, timing: ${JSON.stringify(timing)} => ${localFile}`);
} catch (err: any) {
this.logger.error('Download tarball %s error: %s', tarball, err);
if (err.name === 'DownloadNotFoundError' || err.name === 'DownloadStatusInvalidError') {
this.logger.warn('Download tarball %s error: %s', tarball, err);
} else {
this.logger.error('Download tarball %s error: %s', tarball, err);
}
lastErrorMessage = `download tarball error: ${err}`;
logs.push(`[${isoNow()}] ❌ [${syncIndex}] Synced version ${version} fail, ${lastErrorMessage}`);
await this.taskService.appendTaskLog(task, logs.join('\n'));
Expand Down
15 changes: 14 additions & 1 deletion app/port/schedule/SyncBinaryWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,20 @@ export class SyncBinaryWorker {
this.logger.info('[SyncBinaryWorker:executeTask:start] taskId: %s, targetName: %s, attempts: %s, params: %j, updatedAt: %s, delay %sms',
task.taskId, task.targetName, task.attempts, task.data, task.updatedAt,
startTime - task.updatedAt.getTime());
await this.binarySyncerService.executeTask(task);
try {
await this.binarySyncerService.executeTask(task);
} catch (err) {
const use = Date.now() - startTime;
this.logger.warn('[SyncBinaryWorker:executeTask:error] taskId: %s, targetName: %s, use %sms, error: %s',
task.taskId, task.targetName, use, err.message);
if (err.name === 'ConnectTimeoutError'
|| err.name === 'HttpClientRequestTimeoutError') {
this.logger.warn(err);
} else {
this.logger.error(err);
}
return;
}
const use = Date.now() - startTime;
this.logger.info('[SyncBinaryWorker:executeTask:success] taskId: %s, targetName: %s, use %sms',
task.taskId, task.targetName, use);
Expand Down

0 comments on commit 22d401e

Please sign in to comment.