Skip to content

Commit

Permalink
[O2B-1374] Store only environments with bookkept flag to true (#1776)
Browse files Browse the repository at this point in the history
* [O2B-1374] Store only environments with bookkept flag to true

* Fix linter
  • Loading branch information
martinboulais authored Oct 7, 2024
1 parent e03a151 commit 3aa7b14
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
29 changes: 19 additions & 10 deletions lib/server/kafka/AliEcsSynchronizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
const { AliEcsEventMessagesConsumer } = require('./AliEcsEventMessagesConsumer.js');
const { LogManager } = require('@aliceo2/web-ui');
const { longToBigInt } = require('../utilities/bigIntConverter.js');
const { isAnEmptyShell } = require('../utilities/isAnEmptyShell.js');

const ENVIRONMENT_CONSUMER_GROUP = 'bookkeeping-environment';
const ENVIRONMENT_TOPICS = ['aliecs.environment'];
Expand Down Expand Up @@ -50,16 +51,24 @@ class AliEcsSynchronizer {
const millisecondsTimestamp = Number(bigIntTimestamp / BigInt(1e6));
const nanoSecondsTimestamps = Number(bigIntTimestamp % BigInt(1e9));

await environmentService.createOrUpdateEnvironment(
environmentId,
{
timestamp: millisecondsTimestamp,
timestampNano: nanoSecondsTimestamps,
status: state,
statusMessage: message,
},
vars,
);
const newState = {
timestamp: millisecondsTimestamp,
timestampNano: nanoSecondsTimestamps,
status: state,
statusMessage: message,
};

if (isAnEmptyShell(vars) || vars.bookkept === 'false') {
// We do not know if the environment should be kept or not, update it if it exists, but do not create it
try {
await environmentService.update(environmentId, {}, newState);
} catch (e) {
this._logger.debugMessage('Received message for non-existing environment with empty vars or bookkept false, ignoring it');
}
} else {
// Vars contains value, either `bookkept` is present and is true, either it is not there (old workflows) and we consider it true
await environmentService.createOrUpdateEnvironment(environmentId, newState, vars);
}
});

this.ecsRunConsumer = new AliEcsEventMessagesConsumer(kafkaClient, RUN_CONSUMER_GROUP, RUN_TOPICS);
Expand Down
5 changes: 2 additions & 3 deletions lib/server/services/run/RunService.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const { userService } = require('../user/UserService.js');
const { dataSource } = require('../../../database/DataSource.js');
const { RunDefinition } = require('../../../domain/enums/RunDefinition.js');
const { getEnvironment } = require('../environment/getEnvironment.js');
const { createEnvironment } = require('../environment/createEnvironment.js');
const { getEnvironmentOrFail } = require('../environment/getEnvironmentOrFail.js');
const { EnvironmentConfiguration } = require('../environment/EnvironmentConfiguration.js');
const { TriggerValue } = require('../../../domain/enums/TriggerValue.js');
Expand Down Expand Up @@ -207,9 +206,9 @@ class RunService {
*/
createOrUpdate(runNumber, environmentId, partialRun, relations) {
return dataSource.transaction(async () => {
// If the given environment do not exist yet, create it
// If the given environment do not exist we consider that it should not be stored in database, and same for the runs related to it
if (!await getEnvironment(environmentId)) {
await createEnvironment({ id: environmentId });
return;
}

const existingRun = await getRun({ runNumber });
Expand Down
1 change: 1 addition & 0 deletions proto/ecs/protos/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ message WorkflowTemplateInfo {
string description = 2;
string path = 3;
bool public = 4; // whether the environment is public or not
bool bookkept = 5; // whether the runs should be logged in bookkeeping
}

0 comments on commit 3aa7b14

Please sign in to comment.