Skip to content

Commit d779e6f

Browse files
authored
Merge branch 'main' into dependabot/github_actions/actions/setup-node-6
2 parents ebc5c33 + 70f83b9 commit d779e6f

7 files changed

Lines changed: 67 additions & 28 deletions

File tree

lib/domain/enums/StatusAcronyms.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313

1414
const statusAcronyms = Object.freeze({
15+
PENDING: 'P',
1516
STANDBY: 'S',
1617
DEPLOYED: 'D',
1718
CONFIGURED: 'C',

lib/public/views/Runs/Details/runDetailsComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ export const runDetailsComponent = (runDetailsModel, router) => runDetailsModel.
518518
formatFloat(run.phaseShiftAtStartBeam2) ?? '-',
519519
h('strong', ' | '),
520520
h('small', 'end: '),
521-
formatFloat(run.phaseShiftAtEndBea21) ?? '-',
521+
formatFloat(run.phaseShiftAtEndBeam2) ?? '-',
522522
]),
523523
]),
524524
]),

lib/server/kafka/AliEcsSynchronizer.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,24 @@ class AliEcsSynchronizer {
8585
}
8686

8787
if (transition === 'STOP_ACTIVITY' || transition === 'GO_ERROR') {
88+
const eorReasons = [];
89+
if (userName === 'LHC') {
90+
this._logger.infoMessage(`Run ${runNumber} stopped by LHC user, adding adequate EOR reason`);
91+
eorReasons.push({
92+
category: 'LHC',
93+
title: 'Dump',
94+
description: 'Run stopped due to LHC dump',
95+
});
96+
}
8897
runService
8998
.createOrUpdate(
9099
runNumber,
91100
environmentId,
92101
{ timeO2End: timestamp.toNumber() },
93-
{ userO2Stop: { userIdentifier: { externalUserId }, name: userName } },
102+
{
103+
userO2Stop: { userIdentifier: { externalUserId }, name: userName },
104+
eorReasons,
105+
},
94106
)
95107
.catch((error) => this._logger.errorMessage(`Failed to save run end for ${runNumber}: ${error.message}`));
96108
}

lib/server/services/run/RunService.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,27 +212,28 @@ class RunService {
212212
}
213213

214214
/**
215-
* Get or create a run by its run number, using environment info if it applies
215+
* Create or Update a run by its run number, using environment info if it applies
216216
*
217217
* @param {number} runNumber the run number of the run to create
218218
* @param {string} environmentId the id of the environment containing the run
219219
* @param {Partial<Run>} [partialRun] optional runs properties to define
220220
* @param {Object} [relations] run relations to create/update
221221
* @param {GetOrCreateUserPayload} [relations.userO2Start] if not null, the identifier of the user that started the run
222222
* @param {GetOrCreateUserPayload} [relations.userO2Stop] if not null, the identifier of the user that stopped the run
223+
* @param {EorReason[]} [relations.eorReasons] if not null, the list of end of run reasons to apply to the run (will replace existing ones)
223224
* @return {Promise<Run>} resolves with the run
224225
*/
225226
createOrUpdate(runNumber, environmentId, partialRun, relations) {
226-
return dataSource.transaction(async () => {
227-
// 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
227+
return dataSource.transaction(async (transaction) => {
228+
// If given environment does not exist we should not store the run in database
228229
if (!await getEnvironment(environmentId)) {
229230
return;
230231
}
231232

232233
const existingRun = await getRun({ runNumber });
233234

234235
if (existingRun) {
235-
await this.update({ runNumber }, { runPatch: partialRun, relations });
236+
return await this.update({ runNumber }, { runPatch: partialRun, relations }, transaction);
236237
} else {
237238
const { rawConfiguration } = await getEnvironmentOrFail(environmentId);
238239

@@ -274,9 +275,11 @@ class RunService {
274275
* @param {string|null} [relations.lhcPeriodName=null] if not null, the name of lhc period for which the run should be assigned
275276
* @param {GetOrCreateUserPayload|null} [relations.userO2Start=null] if not null, the identifier of the user that started the run
276277
* @param {GetOrCreateUserPayload|null} [relations.userO2Stop=null] if not null, the identifier of the user that stopped the run
278+
* @param {string[]} [relations.flpRoles] if present, the list of flp roles to create alongside the run
279+
* @param {Object} [transaction] optional transaction where the creation must be done
277280
* @return {Promise<Run>} resolve with the created run instance
278281
*/
279-
async create(newRun, relations) {
282+
async create(newRun, relations, transaction) {
280283
const { runTypeName = null, lhcPeriodName = null, userO2Start = null, userO2Stop = null, flpRoles } = relations || {};
281284

282285
return dataSource.transaction(async () => {
@@ -311,7 +314,7 @@ class RunService {
311314
}
312315

313316
return this.get({ runId }, { runType: true, detectors: true, lhcPeriod: true, flpRoles });
314-
});
317+
}, { transaction });
315318
}
316319

317320
/**
@@ -336,9 +339,10 @@ class RunService {
336339
* @param {GetOrCreateUserPayload|null} [payload.relations.userO2Start=null] if not null, the identifier of the user that started the run
337340
* @param {GetOrCreateUserPayload|null} [payload.relations.userO2Stop=null] if not null, the identifier of the user that stopped the run
338341
* @param {string} [payload.relations.lhcPeriodName] if not null, the name of lhc period for which the run should be assigned
342+
* @param {Object} [transaction] optional transaction where the update must be done
339343
* @return {Promise<Run>} resolve with the resulting run
340344
*/
341-
async update(identifier, payload) {
345+
async update(identifier, payload, transaction) {
342346
const { runPatch = {}, relations = {}, metadata = {} } = payload;
343347
const {
344348
tagsTexts = null, eorReasons = null, runTypeName = null,
@@ -405,7 +409,7 @@ class RunService {
405409

406410
await logRunDetectorQualityChange(run.runNumber, updatedRunDetectors, transaction, user, detectorsQualitiesChangeReason);
407411
}
408-
});
412+
}, { transaction });
409413

410414
return this.get(identifier, { tags: true, runType: true, detectors: true, eorReasons: true, lhcPeriod: true });
411415
}

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aliceo2/bookkeeping",
3-
"version": "1.13.1",
3+
"version": "1.14.0",
44
"author": "ALICEO2",
55
"scripts": {
66
"coverage": "nyc npm test && npm run coverage:report",
@@ -45,14 +45,14 @@
4545
"proto/"
4646
],
4747
"devDependencies": {
48-
"@eslint/js": "^9.38.0",
48+
"@eslint/js": "^9.39.1",
4949
"@stylistic/eslint-plugin-js": "^4.4.1",
5050
"@types/d3": "7.4.0",
5151
"chai": "4.5.0",
5252
"date-and-time": "3.6.0",
5353
"eslint": "^9.36.0",
5454
"eslint-plugin-jsdoc": "^61.1.9",
55-
"globals": "^16.4.0",
55+
"globals": "^16.5.0",
5656
"js-yaml": "4.1.0",
5757
"mocha": "11.7.0",
5858
"nodemon": "3.1.3",

test/lib/server/services/run/RunService.test.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ module.exports = () => {
359359

360360
const run = await runService.update(
361361
{ runNumber },
362-
{ relations: { eorReasons: eorReasons } },
362+
{ relations: { eorReasons } },
363363
);
364364

365365
expect(run.eorReasons).to.lengthOf(2);
@@ -391,7 +391,7 @@ module.exports = () => {
391391

392392
const run = await runService.update(
393393
{ runNumber },
394-
{ relations: { eorReasons: eorReasons } },
394+
{ relations: { eorReasons } },
395395
);
396396

397397
expect(run.eorReasons).to.lengthOf(2);
@@ -431,7 +431,7 @@ module.exports = () => {
431431

432432
const run = await runService.update(
433433
{ runNumber },
434-
{ relations: { eorReasons: eorReasons } },
434+
{ relations: { eorReasons } },
435435
);
436436

437437
// Should only include the valid ones without throwing for invalid one (is simply excluded)
@@ -453,7 +453,7 @@ module.exports = () => {
453453

454454
const run = await runService.update(
455455
{ runNumber },
456-
{ relations: { eorReasons: eorReasons } },
456+
{ relations: { eorReasons } },
457457
);
458458

459459
expect(run.eorReasons).to.lengthOf(0);
@@ -485,7 +485,7 @@ module.exports = () => {
485485

486486
const run = await runService.update(
487487
{ runNumber },
488-
{ relations: { eorReasons: eorReasons } },
488+
{ relations: { eorReasons } },
489489
);
490490

491491
// EorReasons should only include the one that does not have an id
@@ -733,4 +733,26 @@ module.exports = () => {
733733
expect(run.userIdO2Stop).to.equal(2);
734734
expect(run.flpRoles.map(({ name }) => name)).to.deep.equal(['fake-flp1', 'fake-flp2', 'fake-ctp-host']);
735735
});
736+
737+
it('should successfully update a run with provided EOR reasons via the createOrUpdate', async () => {
738+
const run = await runService.createOrUpdate(
739+
1234,
740+
'CmCvjNbg',
741+
{ },
742+
{
743+
eorReasons: [
744+
{
745+
category: 'DETECTORS',
746+
title: 'TPC',
747+
description: 'Run stopped due to LHC dump',
748+
},
749+
],
750+
},
751+
);
752+
// console.log(run);
753+
expect(run.eorReasons).to.have.lengthOf(1);
754+
expect(run.eorReasons[0].category).to.equal('DETECTORS');
755+
expect(run.eorReasons[0].title).to.equal('TPC');
756+
expect(run.eorReasons[0].description).to.equal('Run stopped due to LHC dump');
757+
});
736758
};

0 commit comments

Comments
 (0)