Skip to content

Commit af23655

Browse files
committed
stop wf from overwriting timestamps
1 parent 56683f5 commit af23655

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src/main/java/edu/harvard/iq/dataverse/workflow/WorkflowServiceBean.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -383,42 +383,48 @@ private void pauseAndAwait(Workflow wf, WorkflowContext ctxt, Pending pendingRes
383383

384384
private void workflowCompleted(Workflow wf, WorkflowContext ctxt) {
385385
logger.log(Level.INFO, "Workflow {0} completed.", ctxt.getInvocationId());
386-
387-
try {
386+
387+
// Read fresh timestamps from DB - parallel index/exports may have occurred while the workflow ran
388+
// (Nominally the workflow lock should have stopped other changes).
389+
Dataset dataset = ctxt.getDataset();
390+
Dataset dbDataset = em.find(Dataset.class, ctxt.getDataset().getId());
391+
dataset.setIndexTime(dbDataset.getIndexTime());
392+
dataset.setPermissionIndexTime(dbDataset.getPermissionIndexTime());
393+
dataset.setLastExportTime(dbDataset.getLastExportTime());
394+
395+
try {
388396
if (ctxt.getType() == TriggerType.PrePublishDataset) {
389397
ctxt = refresh(ctxt);
390-
//Now lock for FinalizePublication - this block mirrors that in PublishDatasetCommand
398+
// Now lock for FinalizePublication - this block mirrors that in PublishDatasetCommand
391399
AuthenticatedUser user = ctxt.getRequest().getAuthenticatedUser();
392400
DatasetLock lock = new DatasetLock(DatasetLock.Reason.finalizePublication, user);
393-
Dataset dataset = ctxt.getDataset();
394401
lock.setDataset(dataset);
395-
boolean registerGlobalIdsForFiles =
396-
systemConfig.isFilePIDsEnabledForCollection(ctxt.getDataset().getOwner()) &&
397-
dvObjects.getEffectivePidGenerator(dataset).canCreatePidsLike(dataset.getGlobalId());
398-
402+
boolean registerGlobalIdsForFiles = systemConfig.isFilePIDsEnabledForCollection(ctxt.getDataset().getOwner()) &&
403+
dvObjects.getEffectivePidGenerator(dataset).canCreatePidsLike(dataset.getGlobalId());
404+
399405
boolean validatePhysicalFiles = systemConfig.isDatafileValidationOnPublishEnabled();
400-
String info = "Publishing the dataset; ";
406+
String info = "Publishing the dataset; ";
401407
info += registerGlobalIdsForFiles ? "Registering PIDs for Datafiles; " : "";
402408
info += validatePhysicalFiles ? "Validating Datafiles Asynchronously" : "";
403409
lock.setInfo(info);
404410
lockDataset(ctxt, lock);
405411
ctxt.getDataset().addLock(lock);
406-
412+
407413
unlockDataset(ctxt);
408-
ctxt.setLockId(null); //the workflow lock
409-
//Refreshing merges the dataset
414+
ctxt.setLockId(null); // the workflow lock
415+
// Refreshing merges the dataset
410416
ctxt = refresh(ctxt);
411-
//Then call Finalize
417+
// Then call Finalize
412418
engine.submit(new FinalizeDatasetPublicationCommand(ctxt.getDataset(), ctxt.getRequest(), ctxt.getDatasetExternallyReleased()));
413419
} else {
414420
logger.fine("Removing workflow lock");
415421
unlockDataset(ctxt);
416422
}
417423
} catch (CommandException ex) {
418-
logger.log(Level.SEVERE, "Exception finalizing workflow " + ctxt.getInvocationId() +": " + ex.getMessage(), ex);
419-
rollback(wf, ctxt, new Failure("Exception while finalizing the publication: " + ex.getMessage()), wf.steps.size()-1);
420-
}
421-
424+
logger.log(Level.SEVERE, "Exception finalizing workflow " + ctxt.getInvocationId() + ": " + ex.getMessage(), ex);
425+
rollback(wf, ctxt, new Failure("Exception while finalizing the publication: " + ex.getMessage()), wf.steps.size() - 1);
426+
}
427+
422428
}
423429

424430
public List<Workflow> listWorkflows() {

0 commit comments

Comments
 (0)