@@ -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 }
0 commit comments