Skip to content

Commit edef35b

Browse files
committed
Allow flags creation to continue if initial one fails for sync
1 parent e62d561 commit edef35b

3 files changed

Lines changed: 50 additions & 45 deletions

File tree

lib/server/services/qualityControlFlag/QcFlagService.js

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -156,50 +156,55 @@ class QcFlagService {
156156
const createdFlags = [];
157157
for (const qcFlag of qcFlags) {
158158
const { comment, flagTypeId, origin } = qcFlag;
159-
const { from, to } = this._prepareQcFlagPeriod({ from: qcFlag.from, to: qcFlag.to }, targetRun);
160-
161-
// Insert
162-
const newInstance = await QcFlagRepository.insert({
163-
from,
164-
to,
165-
comment,
166-
origin,
167-
createdById: user.id,
168-
flagTypeId,
169-
runNumber,
170-
detectorId: detector.id,
171-
});
172-
if (dataPass) {
173-
await newInstance.addDataPass(dataPass);
174-
} else if (simulationPass) {
175-
await newInstance.addSimulationPass(simulationPass);
159+
// Each flag should be treated separately and the for loop should not fail on the first error
160+
try {
161+
const { from, to } = this._prepareQcFlagPeriod({ from: qcFlag.from, to: qcFlag.to }, targetRun);
162+
163+
// Insert
164+
const newInstance = await QcFlagRepository.insert({
165+
from,
166+
to,
167+
comment,
168+
origin,
169+
createdById: user.id,
170+
flagTypeId,
171+
runNumber,
172+
detectorId: detector.id,
173+
});
174+
if (dataPass) {
175+
await newInstance.addDataPass(dataPass);
176+
} else if (simulationPass) {
177+
await newInstance.addSimulationPass(simulationPass);
178+
}
179+
180+
/** @var {SequelizeQcFlag} createdFlag */
181+
const createdFlag = await QcFlagRepository.findOne({
182+
where: { id: newInstance.id },
183+
include: [
184+
{ association: 'dataPasses' },
185+
{ association: 'simulationPasses' },
186+
{ association: 'createdBy' },
187+
],
188+
});
189+
190+
// Update effective periods
191+
const effectivePeriodsToBeUpdated = await QcFlagEffectivePeriodRepository.findOverlappingPeriodsCreatedBeforeLimit(
192+
{ from, to },
193+
createdFlag.createdAt,
194+
{ dataPassId: dataPass?.id, simulationPassId: simulationPass?.id, runNumber, detectorId: detector.id },
195+
);
196+
await this._removeEffectivePeriodsAndPeriodIntersection(createdFlag, effectivePeriodsToBeUpdated);
197+
198+
await QcFlagEffectivePeriodRepository.insert({
199+
flagId: newInstance.id,
200+
from: newInstance.from,
201+
to: newInstance.to,
202+
});
203+
204+
createdFlags.push(qcFlagAdapter.toEntity(createdFlag));
205+
} catch (error) {
206+
this._logger.warnMessage(`Failed to create QC flag with properties: ${JSON.stringify(qcFlag)}. Error: ${error}`);
176207
}
177-
178-
/** @var {SequelizeQcFlag} createdFlag */
179-
const createdFlag = await QcFlagRepository.findOne({
180-
where: { id: newInstance.id },
181-
include: [
182-
{ association: 'dataPasses' },
183-
{ association: 'simulationPasses' },
184-
{ association: 'createdBy' },
185-
],
186-
});
187-
188-
// Update effective periods
189-
const effectivePeriodsToBeUpdated = await QcFlagEffectivePeriodRepository.findOverlappingPeriodsCreatedBeforeLimit(
190-
{ from, to },
191-
createdFlag.createdAt,
192-
{ dataPassId: dataPass?.id, simulationPassId: simulationPass?.id, runNumber, detectorId: detector.id },
193-
);
194-
await this._removeEffectivePeriodsAndPeriodIntersection(createdFlag, effectivePeriodsToBeUpdated);
195-
196-
await QcFlagEffectivePeriodRepository.insert({
197-
flagId: newInstance.id,
198-
from: newInstance.from,
199-
to: newInstance.to,
200-
});
201-
202-
createdFlags.push(qcFlagAdapter.toEntity(createdFlag));
203208
}
204209
return createdFlags;
205210
});

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aliceo2/bookkeeping",
3-
"version": "1.9.1",
3+
"version": "1.9.2",
44
"author": "ALICEO2",
55
"scripts": {
66
"coverage": "nyc npm test && npm run coverage:report",

0 commit comments

Comments
 (0)