Skip to content

Commit

Permalink
[backend] Works tracking fail to complete at "update processed time" (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-julien authored and Archidoit committed Jun 3, 2024
1 parent ea360db commit c29c93f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
12 changes: 7 additions & 5 deletions opencti-platform/opencti-graphql/src/database/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,12 @@ export const redisDeleteWorks = async (internalIds: Array<string>) => {
export const redisGetWork = async (internalId: string) => {
return getClientBase().hgetall(internalId);
};
export const isWorkCompleted = async (workId: string) => {
const { import_processed_number: pn, import_expected_number: en } = await redisGetWork(workId);
const total = parseInt(pn, 10);
const expected = parseInt(en, 10);
return { isComplete: total === expected, total, expected };
};
export const redisUpdateWorkFigures = async (workId: string) => {
const timestamp = now();
const clientBase = getClientBase();
Expand All @@ -756,11 +762,7 @@ export const redisUpdateWorkFigures = async (workId: string) => {
await updateObjectCounterRaw(tx, workId, 'import_processed_number', 1);
await updateObjectRaw(tx, workId, { import_last_processed: timestamp });
});
const updatedMetrics = await redisGetWork(workId);
const { import_processed_number: pn, import_expected_number: en }: any = updatedMetrics;
const total = parseInt(pn, 10);
const expected = parseInt(en, 10);
return { isComplete: total === expected, total, expected };
return isWorkCompleted(workId);
};
export const redisGetConnectorStatus = async (connectorId: string) => {
return getClientBase().get(`work:${connectorId}`);
Expand Down
7 changes: 1 addition & 6 deletions opencti-platform/opencti-graphql/src/domain/work.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as R from 'ramda';
import { elDeleteInstances, elIndex, elLoadById, elPaginate, elRawDeleteByQuery, elUpdate, } from '../database/engine';
import { generateWorkId } from '../schema/identifier';
import { INDEX_HISTORY, isNotEmptyField, READ_INDEX_HISTORY } from '../database/utils';
import { redisDeleteWorks, redisGetWork, redisUpdateActionExpectation, redisUpdateWorkFigures } from '../database/redis';
import { isWorkCompleted, redisDeleteWorks, redisUpdateActionExpectation, redisUpdateWorkFigures } from '../database/redis';
import { ENTITY_TYPE_CONNECTOR, ENTITY_TYPE_WORK } from '../schema/internalObject';
import { now, sinceNowInMinutes } from '../utils/format';
import { CONNECTOR_INTERNAL_EXPORT_FILE } from '../schema/general';
Expand Down Expand Up @@ -197,11 +197,6 @@ export const createWork = async (context, user, connector, friendlyName, sourceI
return loadWorkById(context, user, workId);
};

const isWorkCompleted = async (workId) => {
const { import_processed_number: pn, import_expected_number: en } = await redisGetWork(workId);
return { isComplete: parseInt(pn, 10) === parseInt(en, 10), total: pn };
};

export const reportExpectation = async (context, user, workId, errorData) => {
const timestamp = now();
const { isComplete, total } = await redisUpdateWorkFigures(workId);
Expand Down

0 comments on commit c29c93f

Please sign in to comment.