Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions api/src/org/labkey/api/assay/DefaultAssayRunCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.stream.Collectors;

import static java.util.Collections.unmodifiableCollection;
Expand All @@ -123,6 +124,19 @@ public TransformResult transform(AssayRunUploadContext<ProviderType> context, Ex
{
return DataTransformService.get().transformAndValidate(context, run, DataTransformService.TransformOperation.INSERT);
}

/** Issue 26811: If we don't have a view, assume that we are on a background job thread already. */
public static boolean isBackgroundImport(AssayProvider provider, ExpProtocol protocol, boolean forceAsync)
{
return forceAsync || (provider.isBackgroundUpload(protocol) && HttpView.hasCurrentView());
}

/** Queueing a background job only writes the batch and job rows; the import itself takes the lock when the job runs. */
public static Lock[] protocolImportLocks(boolean importInBackground)
{
return importInBackground ? new Lock[0] : new Lock[] { ExperimentService.get().getProtocolImportLock() };
}

/**
* Create and save an experiment run synchronously or asynchronously in a background job depending upon the assay design.
*
Expand All @@ -147,8 +161,10 @@ public Pair<ExpExperiment, ExpRun> saveExperimentRun(
AssayProvider provider = context.getProvider();
ExpProtocol protocol = context.getProtocol();
ExpRun run = null;
// Check if assay protocol is configured to import in the background.
boolean importInBackground = isBackgroundImport(provider, protocol, forceAsync);

try (DbScope.Transaction transaction = ExperimentService.get().getSchema().getScope().ensureTransaction(ExperimentService.get().getProtocolImportLock()))
try (DbScope.Transaction transaction = ExperimentService.get().getSchema().getScope().ensureTransaction(protocolImportLocks(importInBackground)))
{
TransactionAuditProvider.TransactionAuditEvent auditEvent = transaction.getAuditEvent();
if (auditEvent == null)
Expand All @@ -157,9 +173,6 @@ public Pair<ExpExperiment, ExpRun> saveExperimentRun(
AbstractQueryUpdateService.addTransactionAuditEvent(transaction, context.getUser(), auditEvent);
}
context.init();
// Check if assay protocol is configured to import in the background.
// Issue 26811: If we don't have a view, assume that we are on a background job thread already.
boolean importInBackground = forceAsync || (provider.isBackgroundUpload(protocol) && HttpView.hasCurrentView());
if (!importInBackground)
{
if ((Object) context.getUploadedData().get(AssayDataCollector.PRIMARY_FILE) instanceof File errFile)
Expand Down
3 changes: 2 additions & 1 deletion assay/src/org/labkey/assay/actions/ImportRunApiAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,9 @@ else if (rawData != null && !rawData.isEmpty())

boolean success = false;
AssayFilePropertyWriter<? extends AssayProvider> filePropertyWriter = new AssayFilePropertyWriter<>();
boolean importInBackground = DefaultAssayRunCreator.isBackgroundImport(provider, protocol, forceAsync);

try (DbScope.Transaction transaction = ExperimentService.get().getSchema().getScope().ensureTransaction(ExperimentService.get().getProtocolImportLock()))
try (DbScope.Transaction transaction = ExperimentService.get().getSchema().getScope().ensureTransaction(DefaultAssayRunCreator.protocolImportLocks(importInBackground)))
{
Map<TransactionAuditProvider.TransactionDetail, Object> transactionDetails = getTransactionAuditDetails();
if (!StringUtils.isEmpty(auditDetailsJsonStr))
Expand Down
Loading