Skip to content

Commit

Permalink
feat add watcher logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ArceDanielShok committed May 17, 2024
1 parent 079baa3 commit e9f12d4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 53 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "internxt-drive",
"version": "2.0.9",
"version": "2.0.9-qa",
"author": "Internxt <[email protected]>",
"description": "Internxt Drive client UI",
"license": "AGPL-3.0",
Expand Down Expand Up @@ -95,8 +95,7 @@
"win": {
"target": [
"nsis"
],
"certificateSubjectName": "Internxt Universal Technologies SL"
]
},
"linux": {
"target": [
Expand Down
2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "internxt-drive",
"version": "2.0.9",
"version": "2.0.9-qa",
"description": "Internxt Drive client UI",
"main": "./dist/main/main.js",
"author": "Internxt <[email protected]>",
Expand Down
9 changes: 9 additions & 0 deletions src/apps/main/virtual-root-folder/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ function setSyncRoot(pathname: string): void {
'logs',
'node-win.txt'
);

const logWatcherPath = path.join(
app.getPath('appData'),
'internxt-drive',
'logs',
'watcher-win.txt'
);

configStore.set('logEnginePath', logEnginePath);
configStore.set('logWatcherPath', logWatcherPath);
configStore.set('syncRoot', pathNameWithSepInTheEnd);
configStore.set('lastSavedListing', '');
}
Expand Down
62 changes: 16 additions & 46 deletions src/apps/sync-engine/BindingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Logger from 'electron-log';
import * as fs from 'fs';
import { VirtualDrive, QueueItem } from 'virtual-drive/dist';
import { FilePlaceholderId } from '../../context/virtual-drive/files/domain/PlaceholderId';
import { ItemsSearcher } from '../../context/virtual-drive/items/application/ItemsSearcher';
import { PlatformPathConverter } from '../../context/virtual-drive/shared/application/PlatformPathConverter';
import {
IControllers,
Expand All @@ -18,6 +17,7 @@ import { ServerFolderStatus } from '../../context/shared/domain/ServerFolder';
import * as Sentry from '@sentry/electron/renderer';
import { runner } from '../utils/runner';
import { QueueManager } from './dependency-injection/common/QueueManager';
import { DependencyInjectionLogWatcherPath } from './dependency-injection/common/logEnginePath';

export type CallbackDownload = (
success: boolean,
Expand Down Expand Up @@ -169,15 +169,12 @@ export class BindingsManager {
await this.controllers.notifyPlaceholderHydrationFinished.execute(
contentsId
);

await this.container.virtualDrive.closeDownloadMutex();
} catch (error) {
Logger.error('notify: ', error);
Sentry.captureException(error);
await this.container.virtualDrive.closeDownloadMutex();
}

// Esperar hasta que la ejecución de fetchDataCallback esté completa antes de continuar
await new Promise((resolve) => {
setTimeout(() => {
Logger.debug('timeout');
Expand Down Expand Up @@ -258,7 +255,6 @@ export class BindingsManager {

await this.container.virtualDrive.connectSyncRoot();

// run in order the following functions
await runner([this.load.bind(this), this.polling.bind(this)]);
}

Expand Down Expand Up @@ -290,47 +286,17 @@ export class BindingsManager {
},
handleHydrate: async (task: QueueItem) => {
try {
Logger.debug('[Fetch Data Callback] Donwloading begins');
if (!task.fileId) return;
const path = await this.controllers.downloadFile.execute(
task.fileId as FilePlaceholderId
);
const file = this.controllers.downloadFile.fileFinderByContentsId(
task.fileId
.replace(
// eslint-disable-next-line no-control-regex
/[\x00-\x1F\x7F-\x9F]/g,
''
)
.split(':')[1]
);
Logger.debug('[Fetch Data Callback] Preparing begins', path);
Logger.debug('[Handle Hydrate Callback] Preparing begins', task.path);

try {
const result = await this.container.virtualDrive.hydrateFile(
task.path
);
Logger.debug('callback result', result);

ipcRendererSyncEngine.send('FILE_PREPARING', {
name: file.name,
extension: file.type,
nameWithExtension: file.nameWithExtension,
size: file.size,
processInfo: {
elapsedTime: 0,
progress: 1,
},
});
await this.container.virtualDrive.hydrateFile(task.path);

await this.controllers.notifyPlaceholderHydrationFinished.execute(
task.fileId as FilePlaceholderId
);
} catch (error) {
Logger.error('notify: ', error);
Sentry.captureException(error);
await this.container.virtualDrive.closeDownloadMutex();
}
await new Promise((resolve) => {
setTimeout(() => {
Logger.debug('timeout');
resolve(true);
}, 1000);
});
Logger.debug('hydrate result');
} catch (error) {
Logger.error(`error hydrating file ${task.path}`);
Logger.error(error);
Expand Down Expand Up @@ -358,8 +324,12 @@ export class BindingsManager {
}
},
});

this.container.virtualDrive.watchAndWait(this.paths.root, queueManager);
const logWatcherPath = DependencyInjectionLogWatcherPath.get();
this.container.virtualDrive.watchAndWait(
this.paths.root,
queueManager,
logWatcherPath
);
// queueManager.processAll();
}

Expand Down
14 changes: 14 additions & 0 deletions src/apps/sync-engine/dependency-injection/common/logEnginePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@ export class DependencyInjectionLogEnginePath {
return DependencyInjectionLogEnginePath.path;
}
}

export class DependencyInjectionLogWatcherPath {
private static path: string;

static get(): string {
if (DependencyInjectionLogWatcherPath.path) {
return DependencyInjectionLogWatcherPath.path;
}

DependencyInjectionLogWatcherPath.path = configStore.get('logWatcherPath');

return DependencyInjectionLogWatcherPath.path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class ContentsDownloader {
const fileSizeInBytes = stats.size;
const progress = fileSizeInBytes / file.size;

// await this.waitToCb(callback, filePath);
await this.waitToCb(filePath, callback);

this.ipc.send('FILE_DOWNLOADING', {
name: file.name,
Expand Down Expand Up @@ -86,13 +86,15 @@ export class ContentsDownloader {
});
}

private async waitToCb(callback: CallbackDownload, filePath: string) {
private async waitToCb(filePath: string, callback?: CallbackDownload) {
if (
this.progressAt &&
new Date().getTime() - this.progressAt.getTime() >
this.WAIT_TO_SEND_PROGRESS
) {
await callback(true, filePath);
if (callback) {
await callback(true, filePath);
}
this.progressAt = new Date();
}
}
Expand Down

0 comments on commit e9f12d4

Please sign in to comment.