Skip to content

Commit

Permalink
Merge branch 'monitoring-polling-system' of github.com:internxt/drive…
Browse files Browse the repository at this point in the history
…-desktop into fix/ignore-nodes-with-same-name
  • Loading branch information
migueldesarrollosoftware committed Feb 9, 2024
2 parents 03f9e0b + a75c9b1 commit 24eaa05
Show file tree
Hide file tree
Showing 31 changed files with 451 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/apps/renderer/localize/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"login": {
"email": {
"section": "Email adress"
"section": "Email address"
},
"password": {
"section": "Password",
Expand All @@ -11,7 +11,7 @@
"show": "Show"
},
"action": {
"login": "Login",
"login": "Log in",
"is-logging-in": "Logging you in..."
},
"create-account": "Create account",
Expand Down
14 changes: 14 additions & 0 deletions src/apps/sync-engine/BindingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class BindingsManager {

async start(version: string, providerId: string) {
await this.stop();
await this.pollingStart();

const controllers = buildControllers(this.container);

Expand Down Expand Up @@ -215,6 +216,7 @@ export class BindingsManager {

async stop() {
await this.container.virtualDrive.disconnectSyncRoot();
this.container.pollingMonitorStop.run();
}

async cleanUp() {
Expand Down Expand Up @@ -276,4 +278,16 @@ export class BindingsManager {
Logger.error('[SYNC ENGINE] ', error);
}
}

private async pollingStart() {
return this.container.pollingMonitorStart.run(this.polling.bind(this));
}

private async polling(): Promise<void> {
Logger.info('[SYNC ENGINE] Monitoring polling...');
const fileInPendingPaths =
(await this.container.virtualDrive.getPlaceholderWithStatePending()) as Array<string>;
Logger.info('[SYNC ENGINE] fileInPendingPaths', fileInPendingPaths);
await this.container.fileSyncOrchestrator.run(fileInPendingPaths);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class AddController extends CallbackController {
const posixDir =
PlatformPathConverter.getFatherPathPosix(posixRelativePath);
try {
await new Promise((resolve) => setTimeout(resolve, 1000));
await this.runFolderCreator(posixDir);
} catch (error) {
Logger.error('Error creating folder father creation:', error);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { FileCreationOrchestrator } from '../../../../context/virtual-drive/boundaryBridge/application/FileCreationOrchestrator';
import { FileSyncOrchestrator } from '../../../../context/virtual-drive/boundaryBridge/application/FileSyncOrchestrator';

export interface BoundaryBridgeContainer {
fileCreationOrchestrator: FileCreationOrchestrator;
fileSyncOrchestrator: FileSyncOrchestrator;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BoundaryBridgeContainer } from './BoundaryBridgeContainer';
import { ContentsContainer } from '../contents/ContentsContainer';
import { FilesContainer } from '../files/FilesContainer';
import { FileCreationOrchestrator } from '../../../../context/virtual-drive/boundaryBridge/application/FileCreationOrchestrator';
import { FileSyncOrchestrator } from '../../../../context/virtual-drive/boundaryBridge/application/FileSyncOrchestrator';

export function buildBoundaryBridgeContainer(
contentsContainer: ContentsContainer,
Expand All @@ -13,7 +14,13 @@ export function buildBoundaryBridgeContainer(
filesContainer.sameFileWasMoved
);

const fileSyncOrchestrator = new FileSyncOrchestrator(
contentsContainer.contentsUploader,
filesContainer.fileSyncronizer
);

return {
fileCreationOrchestrator,
fileSyncOrchestrator,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ import { FilesPlaceholderCreator } from '../../../../context/virtual-drive/files
import { RepositoryPopulator } from '../../../../context/virtual-drive/files/application/RepositoryPopulator';
import { RetrieveAllFiles } from '../../../../context/virtual-drive/files/application/RetrieveAllFiles';
import { SameFileWasMoved } from '../../../../context/virtual-drive/files/application/SameFileWasMoved';
import { FileSyncronizer } from '../../../../context/virtual-drive/files/application/FileSyncronizer';
import { FilePlaceholderConverter } from '../../../../context/virtual-drive/files/application/FIlePlaceholderConverter';
import { FileSyncStatusUpdater } from '../../../../context/virtual-drive/files/application/FileSyncStatusUpdater';

export interface FilesContainer {
fileFinderByContentsId: FileFinderByContentsId;
fileDeleter: FileDeleter;
filePathUpdater: FilePathUpdater;
fileCreator: FileCreator;
fileSyncronizer: FileSyncronizer;
filePlaceholderCreatorFromContentsId: FilePlaceholderCreatorFromContentsId;
createFilePlaceholderOnDeletionFailed: CreateFilePlaceholderOnDeletionFailed;
sameFileWasMoved: SameFileWasMoved;
retrieveAllFiles: RetrieveAllFiles;
repositoryPopulator: RepositoryPopulator;
filesPlaceholderCreator: FilesPlaceholderCreator;
filesPlaceholderUpdater: FilesPlaceholderUpdater;
filePlaceholderConverter: FilePlaceholderConverter;
fileSyncStatusUpdater: FileSyncStatusUpdater;
}
23 changes: 23 additions & 0 deletions src/apps/sync-engine/dependency-injection/files/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import { SDKRemoteFileSystem } from '../../../../context/virtual-drive/files/inf
import { NodeWinLocalFileSystem } from '../../../../context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem';
import { LocalFileIdProvider } from '../../../../context/virtual-drive/shared/application/LocalFileIdProvider';
import { DependencyInjectionHttpClientsProvider } from '../common/clients';
import { FileSyncronizer } from '../../../../context/virtual-drive/files/application/FileSyncronizer';
import { FilePlaceholderConverter } from '../../../../context/virtual-drive/files/application/FIlePlaceholderConverter';
import { FileSyncStatusUpdater } from '../../../../context/virtual-drive/files/application/FileSyncStatusUpdater';

export async function buildFilesContainer(
folderContainer: FoldersContainer,
Expand Down Expand Up @@ -115,11 +118,29 @@ export async function buildFilesContainer(
eventHistory
);

const filePlaceholderConverter = new FilePlaceholderConverter(
localFileSystem
);

const fileSyncStatusUpdater = new FileSyncStatusUpdater(localFileSystem);

const fileSyncronizer = new FileSyncronizer(
repository,
fileSyncStatusUpdater,
filePlaceholderConverter,
fileCreator,
sharedContainer.absolutePathToRelativeConverter,
folderContainer.folderCreator,
folderContainer.offline.folderCreator,
folderContainer.foldersFatherSyncStatusUpdater
);

const container: FilesContainer = {
fileFinderByContentsId,
fileDeleter,
filePathUpdater,
fileCreator,
fileSyncronizer,
filePlaceholderCreatorFromContentsId: filePlaceholderCreatorFromContentsId,
createFilePlaceholderOnDeletionFailed:
createFilePlaceholderOnDeletionFailed,
Expand All @@ -128,6 +149,8 @@ export async function buildFilesContainer(
repositoryPopulator: repositoryPopulator,
filesPlaceholderCreator,
filesPlaceholderUpdater,
filePlaceholderConverter,
fileSyncStatusUpdater,
};

return { container, subscribers: [] };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { RetrieveAllFolders } from '../../../../context/virtual-drive/folders/ap
import { SynchronizeOfflineModifications } from '../../../../context/virtual-drive/folders/application/SynchronizeOfflineModifications';
import { SynchronizeOfflineModificationsOnFolderCreated } from '../../../../context/virtual-drive/folders/application/SynchronizeOfflineModificationsOnFolderCreated';
import { FolderPlaceholderUpdater } from '../../../../context/virtual-drive/folders/application/UpdatePlaceholderFolder';
import { FolderPlaceholderConverter } from '../../../../context/virtual-drive/folders/application/FolderPlaceholderConverter';
import { FolderSyncStatusUpdater } from '../../../../context/virtual-drive/folders/application/FolderSyncStatusUpdater';
import { FoldersFatherSyncStatusUpdater } from '../../../../context/virtual-drive/folders/application/FoldersFatherSyncStatusUpdater';

export interface FoldersContainer {
folderCreator: FolderCreator;
Expand All @@ -30,4 +33,7 @@ export interface FoldersContainer {
folderRepositoryInitiator: FolderRepositoryInitiator;
folderPlaceholderUpdater: FolderPlaceholderUpdater;
foldersPlaceholderCreator: FoldersPlaceholderCreator;
folderPlaceholderConverter: FolderPlaceholderConverter;
folderSyncStatusUpdater: FolderSyncStatusUpdater;
foldersFatherSyncStatusUpdater: FoldersFatherSyncStatusUpdater;
}
25 changes: 23 additions & 2 deletions src/apps/sync-engine/dependency-injection/folders/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import { DependencyInjectionEventRepository } from '../common/eventRepository';
import { DependencyInjectionVirtualDrive } from '../common/virtualDrive';
import { SharedContainer } from '../shared/SharedContainer';
import { FoldersContainer } from './FoldersContainer';
import { FolderPlaceholderConverter } from '../../../../context/virtual-drive/folders/application/FolderPlaceholderConverter';
import { FolderSyncStatusUpdater } from '../../../../context/virtual-drive/folders/application/FolderSyncStatusUpdater';
import { FoldersFatherSyncStatusUpdater } from '../../../../context/virtual-drive/folders/application/FoldersFatherSyncStatusUpdater';

export async function buildFoldersContainer(
shredContainer: SharedContainer
Expand All @@ -38,12 +41,21 @@ export async function buildFoldersContainer(

const repository = new InMemoryFolderRepository();

const localFileSystem = new NodeWinLocalFileSystem(virtualDrive);
const localFileSystem = new NodeWinLocalFileSystem(
virtualDrive,
shredContainer.relativePathToAbsoluteConverter
);
const remoteFileSystem = new HttpRemoteFileSystem(
clients.drive,
clients.newDrive
);

const folderPlaceholderConverter = new FolderPlaceholderConverter(
localFileSystem
);

const folderSyncStatusUpdater = new FolderSyncStatusUpdater(localFileSystem);

const folderFinder = new FolderFinder(repository);

const allParentFoldersStatusIsExists = new AllParentFoldersStatusIsExists(
Expand All @@ -61,7 +73,8 @@ export async function buildFoldersContainer(
repository,
remoteFileSystem,
ipcRendererSyncEngine,
eventBus
eventBus,
folderPlaceholderConverter
);

const folderMover = new FolderMover(
Expand Down Expand Up @@ -124,6 +137,11 @@ export async function buildFoldersContainer(
shredContainer.relativePathToAbsoluteConverter
);

const foldersFatherSyncStatusUpdater = new FoldersFatherSyncStatusUpdater(
localFileSystem,
repository
);

return {
folderCreator,
folderFinder,
Expand All @@ -141,5 +159,8 @@ export async function buildFoldersContainer(
folderRepositoryInitiator,
foldersPlaceholderCreator,
folderPlaceholderUpdater,
folderPlaceholderConverter,
folderSyncStatusUpdater,
foldersFatherSyncStatusUpdater,
};
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { AbsolutePathToRelativeConverter } from '../../../../context/virtual-drive/shared/application/AbsolutePathToRelativeConverter';
import { PollingMonitorStart } from '../../../../context/virtual-drive/shared/application/PollingMonitorStart';
import { PollingMonitorStop } from '../../../../context/virtual-drive/shared/application/PollingMonitorStop';
import { RelativePathToAbsoluteConverter } from '../../../../context/virtual-drive/shared/application/RelativePathToAbsoluteConverter';

export interface SharedContainer {
absolutePathToRelativeConverter: AbsolutePathToRelativeConverter;
relativePathToAbsoluteConverter: RelativePathToAbsoluteConverter;
pollingMonitorStart: PollingMonitorStart;
pollingMonitorStop: PollingMonitorStop;
}
10 changes: 10 additions & 0 deletions src/apps/sync-engine/dependency-injection/shared/builder.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { AbsolutePathToRelativeConverter } from '../../../../context/virtual-drive/shared/application/AbsolutePathToRelativeConverter';
import { PollingMonitorStart } from '../../../../context/virtual-drive/shared/application/PollingMonitorStart';
import { PollingMonitorStop } from '../../../../context/virtual-drive/shared/application/PollingMonitorStop';
import { RelativePathToAbsoluteConverter } from '../../../../context/virtual-drive/shared/application/RelativePathToAbsoluteConverter';
import { PollingMonitor } from '../../../../context/virtual-drive/shared/domain/PollingMonitor';
import { DependencyInjectionLocalRootFolderPath } from '../common/localRootFolderPath';
import { SharedContainer } from './SharedContainer';

export function buildSharedContainer(): SharedContainer {
const MONITORING_PULLING_INTERVAL = 60 * 60 * 1000;
const localRootFolderPath = DependencyInjectionLocalRootFolderPath.get();
const absolutePathToRelativeConverter = new AbsolutePathToRelativeConverter(
localRootFolderPath
Expand All @@ -13,8 +17,14 @@ export function buildSharedContainer(): SharedContainer {
localRootFolderPath
);

const pollingMonitor = new PollingMonitor(MONITORING_PULLING_INTERVAL);
const pollingMonitorStart = new PollingMonitorStart(pollingMonitor);
const pollingMonitorStop = new PollingMonitorStop(pollingMonitor);

return {
absolutePathToRelativeConverter,
relativePathToAbsoluteConverter,
pollingMonitorStart,
pollingMonitorStop,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { RetryContentsUploader } from '../../contents/application/RetryContentsUploader';
import { FileSyncronizer } from '../../files/application/FileSyncronizer';

export class FileSyncOrchestrator {
constructor(
private readonly contentsUploader: RetryContentsUploader,
private readonly fileSyncronizer: FileSyncronizer
) {}

run(absolutePaths: string[]): Promise<void[]> {
return Promise.all(
absolutePaths.map(async (absolutePath) => {
await this.fileSyncronizer.run(
absolutePath,
this.contentsUploader.run.bind(this.contentsUploader)
);
})
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { File } from '../domain/File';
import { LocalFileSystem } from '../domain/file-systems/LocalFileSystem';

export class FilePlaceholderConverter {
constructor(private readonly localFileSystem: LocalFileSystem) {}

async run(file: File) {
await this.localFileSystem.convertToPlaceholder(file);
}
}
13 changes: 13 additions & 0 deletions src/context/virtual-drive/files/application/FileContentsUpdater.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// import { FileRepository } from '../domain/FileRepository';
// import { RemoteFileSystem } from '../domain/file-systems/RemoteFileSystem';

// export class FileContentsUpdater {
// constructor(
// private readonly repository: FileRepository,
// private readonly remote: RemoteFileSystem
// ) {}

// async run(file: File): Promise<void> {
// await this.local.updateSyncStatus(file);
// }
// }
20 changes: 13 additions & 7 deletions src/context/virtual-drive/files/application/FileCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,21 @@ export class FileCreator {
private readonly ipc: SyncEngineIpc
) {}

async run(filePath: FilePath, contents: RemoteFileContents): Promise<File> {
async run(
filePath: FilePath,
contents: RemoteFileContents,
existingFileAlreadyEvaluated = false
): Promise<File> {
try {
const existingFile = this.repository.searchByPartial({
path: PlatformPathConverter.winToPosix(filePath.value),
status: FileStatuses.EXISTS,
});
if (!existingFileAlreadyEvaluated) {
const existingFile = this.repository.searchByPartial({
path: PlatformPathConverter.winToPosix(filePath.value),
status: FileStatuses.EXISTS,
});

if (existingFile) {
await this.fileDeleter.run(existingFile.contentsId);
if (existingFile) {
await this.fileDeleter.run(existingFile.contentsId);
}
}

const size = new FileSize(contents.size);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { File } from '../domain/File';
import { LocalFileSystem } from '../domain/file-systems/LocalFileSystem';

export class FileSyncStatusUpdater {
constructor(private readonly localFileSystem: LocalFileSystem) {}

async run(file: File) {
await this.localFileSystem.updateSyncStatus(file);
}
}
Loading

0 comments on commit 24eaa05

Please sign in to comment.