Skip to content

Commit

Permalink
Avoid sending empty queue
Browse files Browse the repository at this point in the history
  • Loading branch information
hauck-jvsh committed Feb 19, 2025
1 parent d9b9fd1 commit db482be
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ private void sendItemsToNextTask() throws Exception {
// criar zip um com i.getThumb() de todos os itens
System.out.println("Envia fila de tamanho" + queue.size());
try (TemporaryResources tmp = new TemporaryResources()) {
File zipFile = tmp.createTemporaryFile();
try (FileOutputStream fos = new FileOutputStream(zipFile); ZipOutputStream zos = new ZipOutputStream(fos)) {
for (String name : queue.keySet()) {
addFileToZip(name, queue.get(name).getThumb(), zos);
}
if (queue.size() > 0) {
File zipFile = tmp.createTemporaryFile();
try (FileOutputStream fos = new FileOutputStream(zipFile);
ZipOutputStream zos = new ZipOutputStream(fos)) {
for (String name : queue.keySet()) {
addFileToZip(name, queue.get(name).getThumb(), zos);
}

}
sendZipFile(zipFile);
}
sendZipFile(zipFile);
} finally {
for (IItem item : queue.values()) {
if (item != null) {
Expand Down Expand Up @@ -138,14 +141,14 @@ private void sendZipFile(File zipFile) throws IOException {
}

protected void sendToNextTask(IItem item) throws Exception {
if (!isEnabled() || !queue.containsValue(item)) {
if (!isEnabled()) {
super.sendToNextTask(item);
return;
}
if (queue.size() >= 50 || item.isQueueEnd()) {
if (queue.size() > 0 && (queue.size() >= 50 || item.isQueueEnd())) {
sendItemsToNextTask();
}
if (item.isQueueEnd()) {
if (!queue.containsValue(item) || item.isQueueEnd()) {
super.sendToNextTask(item);
}

Expand All @@ -160,7 +163,7 @@ protected boolean processQueueEnd() {

@Override
protected void process(IItem evidence) throws Exception {
if (evidence.isQueueEnd()) {
if (evidence.isQueueEnd() && queue.size() > 0) {
sendItemsToNextTask();
return;
}
Expand Down

0 comments on commit db482be

Please sign in to comment.