Add ML logging (#1504)

This commit is contained in:
Abhinav Kumar 2023-12-13 12:56:08 +05:30 committed by GitHub
commit ebc03b5a69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 29 deletions

View file

@ -211,7 +211,7 @@ class DownloadManagerImpl {
this.thumbnailObjectURLPromises.set(file.id, thumbURLPromise);
}
let thumb = await this.thumbnailObjectURLPromises.get(file.id);
if (!thumb) {
if (!thumb && !localOnly) {
this.thumbnailObjectURLPromises.delete(file.id);
thumb = await this.getThumbnailForPreview(file, localOnly);
}

View file

@ -201,35 +201,39 @@ class MLWorkManager {
}
private async runMLSyncJob(): Promise<MLSyncJobResult> {
// TODO: skipping is not required if we are caching chunks through service worker
// currently worker chunk itself is not loaded when network is not there
if (!navigator.onLine) {
addLogLine(
'Skipping ml-sync job run as not connected to internet.'
);
return {
shouldBackoff: true,
mlSyncResult: undefined,
try {
// TODO: skipping is not required if we are caching chunks through service worker
// currently worker chunk itself is not loaded when network is not there
if (!navigator.onLine) {
addLogLine(
'Skipping ml-sync job run as not connected to internet.'
);
return {
shouldBackoff: true,
mlSyncResult: undefined,
};
}
const token = getToken();
const userID = getUserID();
const jobWorkerProxy = await this.getSyncJobWorker();
const mlSyncResult = await jobWorkerProxy.sync(token, userID);
// this.terminateSyncJobWorker();
const jobResult: MLSyncJobResult = {
shouldBackoff:
!!mlSyncResult.error || mlSyncResult.nOutOfSyncFiles < 1,
mlSyncResult,
};
addLogLine('ML Sync Job result: ', JSON.stringify(jobResult));
// TODO: redirect/refresh to gallery in case of session_expired, stop ml sync job
return jobResult;
} catch (e) {
logError(e, 'Failed to run MLSync Job');
}
const token = getToken();
const userID = getUserID();
const jobWorkerProxy = await this.getSyncJobWorker();
const mlSyncResult = await jobWorkerProxy.sync(token, userID);
// this.terminateSyncJobWorker();
const jobResult: MLSyncJobResult = {
shouldBackoff:
!!mlSyncResult.error || mlSyncResult.nOutOfSyncFiles < 1,
mlSyncResult,
};
addLogLine('ML Sync Job result: ', JSON.stringify(jobResult));
// TODO: redirect/refresh to gallery in case of session_expired, stop ml sync job
return jobResult;
}
public async startSyncJob() {

View file

@ -1,6 +1,7 @@
import { expose, Remote, wrap } from 'comlink';
import { WorkerSafeElectronClient } from '@ente/shared/electron/worker/client';
import { addLocalLog } from '@ente/shared/logging';
import { logError } from '../sentry';
export class ComlinkWorker<T extends new () => InstanceType<T>> {
public remote: Promise<Remote<InstanceType<T>>>;
@ -12,7 +13,10 @@ export class ComlinkWorker<T extends new () => InstanceType<T>> {
this.worker = worker;
this.worker.onerror = (errorEvent) => {
console.error('Got error event from worker', errorEvent);
logError(Error(errorEvent.message), 'Got error event from worker', {
errorEvent: JSON.stringify(errorEvent),
name: this.name,
});
};
addLocalLog(() => `Initiated ${this.name}`);
const comlink = wrap<T>(this.worker);