Skip to content

Commit

Permalink
Stop processing tasks by schedulers on remove of the Polling Interval…
Browse files Browse the repository at this point in the history
… from the configuration immediately Fix #1390
  • Loading branch information
gunterze committed May 13, 2018
1 parent f5d7ae7 commit 6e4239b
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,12 @@ protected void execute() {
} catch (IOException e) {
LOG.warn("Failed to access Audit Spool Directory - {}", dir, e);
}
for (Path path : pathList)
for (Path path : pathList) {
if (getPollingInterval() == null)
return;

service.auditAndProcessFile(logger, path);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ private void rejectExpiredSeries(
.setMaxResults(seriesFetchSize)
.getResultList();
for (Series series : seriesList) {
if (getPollingInterval() == null)
return;

try {
reject(ae, series.getStudy().getStudyInstanceUID(), series.getSeriesInstanceUID(), rn, rejectionNoteObjectStorageID);
} catch (IOException e) {
Expand All @@ -191,6 +194,9 @@ private void rejectExpiredStudies(
.setMaxResults(studyFetchSize)
.getResultList();
for (Study study : studies) {
if (getPollingInterval() == null)
return;

try {
reject(ae, study.getStudyInstanceUID(), null, rn, rejectionNoteObjectStorageID);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ private void delete(String queryName, Code rjCode, Duration delay, int fetchSize
Date before = new Date(System.currentTimeMillis() - delay.getSeconds() * 1000);
int deleted;
do {
if (getPollingInterval() == null)
return;
deleted = ejb.deleteRejectedInstancesOrRejectionNotesBefore(queryName, rjCode, before, fetchSize);
} while (deleted == fetchSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,14 @@ protected void execute() {
Map<String, Storage> storageMap = new HashMap<>();
try {
do {
if (getPollingInterval() == null)
return;

series = ejb.findSeriesToPurgeInstances(fetchSize);
for (Series.MetadataUpdate metadataUpdate : series) {
if (getPollingInterval() == null)
return;

Long seriesPk = metadataUpdate.seriesPk;
if (!claim(seriesPk))
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ protected void execute() {
BinaryPrefix.formatDecimal(minUsableSpace), BinaryPrefix.formatDecimal(deleteSize));
}
for (int i = 0; i == 0 || deleteSize > 0L; i++) {
if (getPollingInterval() == null)
return;
if (deleteSize > 0L) {
if (deleteStudies(desc, deleteStudyBatchSize, deletePatient) == 0)
deleteSize = 0L;
Expand Down Expand Up @@ -274,6 +276,8 @@ private static boolean matchStorageID(Attributes attrs, String storageID) {
private int deleteStudiesFromDB(StorageDescriptor desc, List<Long> studyPks, boolean deletePatient) {
int removed = 0;
for (Long studyPk : studyPks) {
if (getPollingInterval() == null)
break;
StudyDeleteContextImpl ctx = new StudyDeleteContextImpl(studyPk);
ctx.setDeletePatientOnDeleteLastStudy(deletePatient);
try {
Expand All @@ -297,6 +301,8 @@ private int deleteStudiesFromDB(StorageDescriptor desc, List<Long> studyPks, boo
private int deleteObjectsOfStudies(StorageDescriptor desc, List<Long> studyPks) {
int removed = 0;
for (Long studyPk : studyPks) {
if (getPollingInterval() == null)
break;
try {
Study study = ejb.deleteObjectsOfStudy(studyPk, desc.getStorageID());
removed++;
Expand All @@ -315,6 +321,8 @@ private boolean deleteSeriesMetadata(StorageDescriptor desc, int fetchSize) {

try (Storage storage = storageFactory.getStorage(desc)) {
for (Metadata m : metadata) {
if (getPollingInterval() == null)
return false;
try {
storage.deleteObject(m.getStoragePath());
ejb.removeMetadata(m);
Expand All @@ -337,6 +345,8 @@ private boolean deleteNextObjectsFromStorage(StorageDescriptor desc, int fetchSi

try (Storage storage = storageFactory.getStorage(desc)) {
for (Location location : locations) {
if (getPollingInterval() == null)
return false;
try {
storage.deleteObject(location.getStoragePath());
ejb.removeLocation(location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected Duration getPollingInterval() {
protected void execute() {
ArchiveDeviceExtension arcDev = device.getDeviceExtension(ArchiveDeviceExtension.class);
int fetchSize = arcDev.getExportTaskFetchSize();
while (ejb.scheduleExportTasks(fetchSize) == fetchSize)
while (getPollingInterval() != null && ejb.scheduleExportTasks(fetchSize) == fetchSize)
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ protected void execute() {
List<HL7PSUTask> hl7psuTasks;
do {
hl7psuTasks = ejb.fetchHL7PSUTasksForMPPS(device.getDeviceName(), hl7psuTaskPk, fetchSize);
for (HL7PSUTask hl7psuTask : hl7psuTasks)
for (HL7PSUTask hl7psuTask : hl7psuTasks) {
if (getPollingInterval() == null)
return;

try {
hl7psuTaskPk = hl7psuTask.getPk();
ApplicationEntity ae = device.getApplicationEntity(hl7psuTask.getAETitle());
Expand All @@ -115,10 +118,14 @@ protected void execute() {
} catch (Exception e) {
LOG.warn("Failed to process {}:\n", hl7psuTask, e);
}
}
} while (hl7psuTasks.size() == fetchSize);
do {
hl7psuTasks = ejb.fetchHL7PSUTasksForStudy(device.getDeviceName(), fetchSize);
for (HL7PSUTask hl7psuTask : hl7psuTasks) {
if (getPollingInterval() == null)
return;

ApplicationEntity ae = device.getApplicationEntity(hl7psuTask.getAETitle());
ArchiveAEExtension arcAE = ae.getAEExtension(ArchiveAEExtension.class);
HL7PSU action = hl7PSUActionOnStudy(arcAE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ protected void execute() {
Attributes ian;
do {
ianTasks = ejb.fetchIANTasksForMPPS(device.getDeviceName(), ianTaskPk, fetchSize);
for (IanTask ianTask : ianTasks)
for (IanTask ianTask : ianTasks) {
if (getPollingInterval() == null)
return;

try {
ianTaskPk = ianTask.getPk();
ApplicationEntity ae = device.getApplicationEntity(ianTask.getCallingAET(), true);
Expand All @@ -116,10 +119,14 @@ protected void execute() {
} catch (Exception e) {
LOG.warn("Failed to process {}", ianTask, e);
}
}
} while (ianTasks.size() == fetchSize);
do {
ianTasks = ejb.fetchIANTasksForStudy(device.getDeviceName(), fetchSize);
for (IanTask ianTask : ianTasks)
for (IanTask ianTask : ianTasks) {
if (getPollingInterval() == null)
return;

try {
ApplicationEntity ae = device.getApplicationEntity(ianTask.getCallingAET(), true);
if (ianTask.getMpps() == null) {
Expand All @@ -146,6 +153,7 @@ protected void execute() {
} catch (Exception e) {
LOG.warn("Failed to process {}", ianTask, e);
}
}
} while (ianTasks.size() == fetchSize);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ protected void execute() {
if (!metadataUpdates.isEmpty())
try (Storage storage = storageFactory.getUsableStorage(descriptors)) {
for (Series.MetadataUpdate metadataUpdate : metadataUpdates) {
if (getPollingInterval() == null)
return;

try (RetrieveContext ctx = retrieveService.newRetrieveContextSeriesMetadata(metadataUpdate)) {
updateMetadata(ctx, storage);
} catch (Exception e) {
Expand Down

0 comments on commit 6e4239b

Please sign in to comment.