Commit d3ede75d authored by Clément Berthou's avatar Clément Berthou
Browse files

feat: add debug logging

parent 083b0412
import path from "path";
import { tap } from "rxjs/operators";
import { reportError } from "logging/reporter";
import {reportError, reportInfo} from "logging/reporter";
import { ArchifiltreThunkAction } from "reducers/archifiltre-types";
import {
getFilesAndFoldersFromStore,
......@@ -38,6 +37,8 @@ import {
} from "reducers/hashes/hashes-selectors";
import { getWorkspaceMetadataFromStore } from "reducers/workspace-metadata/workspace-metadata-selectors";
import { ArchifiltreError } from "util/error/error-util";
import { tap } from "rxjs/operators";
import { tap as fpTap } from "util/functionnal-programming-utils";
const computeFileHashesIgnoredThunk = (
loadingActionId: string,
......@@ -56,6 +57,7 @@ const computeFileHashesImplThunk = (
): Promise<number> => {
let loadingErrorsCount = 0;
reportInfo("Loading file hashes...");
const basePath = originalPath.split(path.sep).slice(0, -1).join(path.sep);
const hashes$ = computeHashes$(fileIds, { initialValues: { basePath } });
......@@ -80,7 +82,7 @@ const computeFileHashesImplThunk = (
}).subscribe({
complete: () => resolve(loadingErrorsCount),
});
});
}).then(fpTap<number>(() => reportInfo("Loaded file hashes")));
};
type ComputeFileHashesThunkOptions = {
......@@ -111,7 +113,7 @@ const computeFileHashesThunk = (
const computeFolderHashesThunk = (
loadingActionId: string
): ArchifiltreThunkAction<Promise<void>> => async (dispatch, getState) => {
return new Promise((resolve) => {
return new Promise<void>((resolve) => {
const state = getState();
const hashes = getHashesFromStore(state);
const filesAndFolders = getFilesAndFoldersFromStore(state);
......@@ -122,13 +124,15 @@ const computeFolderHashesThunk = (
dispatch(setFilesAndFoldersHashes(newHashes));
};
reportInfo("Loading folder hashes");
computeFolderHashes$({ filesAndFolders, hashes }).subscribe({
complete: () => {
resolve();
},
next: onNewHashesComputed,
});
});
}).then(fpTap<void>(() => { reportInfo("FolderHashesLoaded") }));
};
type ComputeHashesThunkOptions = {
......
import _ from "lodash";
import { compose } from "lodash/fp";
import { reportError } from "logging/reporter";
import {reportError, reportInfo} from "logging/reporter";
import path from "path";
import { mapToNewVersionNumbers } from "components/header/new-version-checker";
import { firstHashesComputingThunk } from "hash-computer/hash-computer-thunk";
......@@ -315,6 +315,7 @@ const loadFilesAndFoldersAfterInitThunk = (
erroredPaths?: ArchifiltreError[];
} = {}
): ArchifiltreThunkAction<VirtualFileSystemLoader> => (dispatch) => {
reportInfo(`Loading path : ${fileOrFolderPath}`);
const { result$, terminate } = loadFileTree(fileOrFolderPath, {
filesAndFolders,
erroredPaths,
......@@ -330,6 +331,7 @@ const loadFilesAndFoldersAfterInitThunk = (
.toPromise()
.then(({ result: { result } }) => {
dispatch(handleVirtualFileSystemThunk(fileOrFolderPath, result));
reportInfo(`Filesystem loaded : ${fileOrFolderPath}`);
return result;
});
......
import {AsyncWorker} from "./async-worker-util";
import {MessageTypes} from "../batch-process/batch-process-util-types";
export const logInfo = (asyncWorker: AsyncWorker) => (data: string) => {
asyncWorker.postMessage({
type: MessageTypes.LOG,
data
});
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import {
} from "../batch-process/batch-process-util-types";
import translations from "translations/translations";
import { ChildProcess } from "child_process";
import { logInfo } from "./async-worker-logger";
export enum WorkerEventType {
MESSAGE = "message",
......@@ -48,6 +49,7 @@ export const makeChildWorkerMessageCallback = (
asyncWorker: AsyncWorker,
{ onInitialize, onData }: SetupChildWorkerListenersOptions
) => async ({ data, type }: any) => {
const info = logInfo(asyncWorker);
switch (type) {
case MessageTypes.INITIALIZE:
if (data.language) {
......@@ -57,10 +59,14 @@ export const makeChildWorkerMessageCallback = (
break;
}
try {
info("Before initialize");
await onInitialize(asyncWorker, data);
info("afterInitialize");
asyncWorker.postMessage({ type: MessageTypes.READY });
} catch (err) {
console.error(err);
info("Before fatal");
info(`Before fatal ${err.toString()}`);
asyncWorker.postMessage({
type: MessageTypes.FATAL,
error: err.toString(),
......@@ -73,9 +79,13 @@ export const makeChildWorkerMessageCallback = (
break;
}
try {
info("Before data");
await onData(asyncWorker, data);
info("After data");
} catch (err) {
console.error(err);
info("Before data fatal");
info(`Before data fatal : ${err.toString()}`);
asyncWorker.postMessage({
type: MessageTypes.FATAL,
error: err.toString(),
......@@ -96,8 +106,12 @@ export const setupChildWorkerListeners = (
asyncWorker: AsyncWorker,
listeners: SetupChildWorkerListenersOptions
) => {
asyncWorker.addEventListener(
WorkerEventType.MESSAGE,
makeChildWorkerMessageCallback(asyncWorker, listeners)
);
try {
asyncWorker.addEventListener(
WorkerEventType.MESSAGE,
makeChildWorkerMessageCallback(asyncWorker, listeners)
);
} catch (err) {
logInfo(asyncWorker)("Setting up listeners");
}
};
import { cpus } from "os";
import { fromEvent, merge, Observable, Subject } from "rxjs";
import { reportError } from "logging/reporter";
import {reportError, reportInfo} from "logging/reporter";
import { makeEmptyArray } from "util/array/array-util";
import { filter, map, take, takeWhile, tap } from "rxjs/operators";
import {
......@@ -201,7 +201,7 @@ export const cancelableBackgroundWorkerProcess$ = (
reportError(message.error);
}),
onMessageType(MessageTypes.LOG, (message) => {
console.log("Logging :", message.data);
reportInfo(`Worker message : ${message.data}`);
}),
filter<WorkerMessage, ErrorMessage | ResultMessage>(
(message: WorkerMessage): message is ResultMessage | ErrorMessage =>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment