Skip to content

Commit

Permalink
Fixed two issues #2053 and #2202
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev committed Sep 20, 2020
1 parent 4a80959 commit 928c77b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cvat-core/src/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class LogWithExceptionInfo extends Log {

dump() {
let body = super.dump();
const payload = body.payload;
const { payload } = body;
const client = detect();
body = {
...body,
Expand Down
29 changes: 22 additions & 7 deletions cvat-core/src/logger-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ const { LogType } = require('./enums');

const WORKING_TIME_THRESHOLD = 100000; // ms, 1.66 min

function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}

class LoggerStorage {
constructor() {
this.clientID = Date.now().toString().substr(-6);
Expand All @@ -22,6 +28,7 @@ class LoggerStorage {
this.collection = [];
this.ignoreRules = {}; // by event
this.isActiveChecker = null;
this.saving = false;

this.ignoreRules[LogType.zoomImage] = {
lastLog: null,
Expand Down Expand Up @@ -146,6 +153,10 @@ LoggerStorage.prototype.log.implementation = function (logType, payload, wait) {
};

LoggerStorage.prototype.save.implementation = async function () {
while (this.saving) {
await sleep(100);
}

const collectionToSend = [...this.collection];
const lastLog = this.collection[this.collection.length - 1];

Expand All @@ -164,14 +175,18 @@ LoggerStorage.prototype.save.implementation = async function () {
const userActivityLog = logFactory(LogType.sendUserActivity, logPayload);
collectionToSend.push(userActivityLog);

await serverProxy.logs.save(collectionToSend.map((log) => log.dump()));

for (const rule of Object.values(this.ignoreRules)) {
rule.lastLog = null;
try {
this.saving = true;
await serverProxy.logs.save(collectionToSend.map((log) => log.dump()));
for (const rule of Object.values(this.ignoreRules)) {
rule.lastLog = null;
}
this.collection = [];
this.workingTime = 0;
this.lastLogTime = Date.now();
} finally {
this.saving = false;
}
this.collection = [];
this.workingTime = 0;
this.lastLogTime = Date.now();
};

module.exports = new LoggerStorage();
9 changes: 5 additions & 4 deletions cvat-ui/src/actions/annotation-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ export function getJobAsync(
export function saveAnnotationsAsync(sessionInstance: any):
ThunkAction {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
const { filters, frame, showAllInterpolationTracks } = receiveAnnotationsParameters();
const { filters, showAllInterpolationTracks } = receiveAnnotationsParameters();

dispatch({
type: AnnotationActionTypes.SAVE_ANNOTATIONS,
Expand All @@ -1021,16 +1021,17 @@ ThunkAction {
},
});
});

const states = await sessionInstance
.annotations.get(frame, showAllInterpolationTracks, filters);
await saveJobEvent.close();
await sessionInstance.logger.log(
LogType.sendTaskInfo,
await jobInfoGenerator(sessionInstance),
);
dispatch(saveLogsAsync());

const { frame } = receiveAnnotationsParameters();
const states = await sessionInstance
.annotations.get(frame, showAllInterpolationTracks, filters);

dispatch({
type: AnnotationActionTypes.SAVE_ANNOTATIONS_SUCCESS,
payload: {
Expand Down

0 comments on commit 928c77b

Please sign in to comment.