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
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ public void run() {
logger.warn("Rejected reprocess for channel {} referencing unknown metadata column: {}", e.getChannelId(), e.getColumnName());
} catch (ControllerException e) {
logger.error("Error reprocessing messages for channel " + channelId + ": " + e.getMessage(), e);
} catch (Throwable t) {
// Anything else would end this thread with nothing in the server log.
logger.error("Error reprocessing messages for channel " + channelId, t);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,10 @@ public void reprocessMessages(String channelId, MessageFilter filter, boolean re
engineController.dispatchRawMessage(channelId, rawMessage, true, false);
} catch (SerializerException e) {
logger.error("Could not reprocess message " + messageId + " for channel " + channelId + " because the source map content is invalid.", e);
} catch (ChannelException e) {
if (e.isStopped()) {
// This should only return true if the entire channel is stopped, since we are forcing the message even if the source connector is stopped.
logger.error("Reprocessing job cancelled because the channel is stopping or stopped.", e);
} catch (Throwable e) {
if (logReprocessFailure(logger, channelId, messageId, e)) {
return;
}
} catch (Throwable e) {
// Do nothing. An error should have been logged.
}
} else {
logger.error("Could not reprocess message " + messageId + " for channel " + channelId + " because no source raw content was found. The content may have been pruned or the channel may not be configured to store raw content.");
Expand All @@ -476,6 +472,23 @@ public void reprocessMessages(String channelId, MessageFilter filter, boolean re
}
}

/**
* Logs a message that could not be dispatched during a reprocess. Reprocessing runs on its own
* thread after the request has returned, so the server log is the only place the failure can be
* reported. Returns true when the whole job should stop because the channel is stopping or
* stopped; any other failure is logged and the job moves on to the next message.
*/
static boolean logReprocessFailure(Logger logger, String channelId, long messageId, Throwable error) {
if (error instanceof ChannelException && ((ChannelException) error).isStopped()) {
// This should only return true if the entire channel is stopped, since we are forcing the message even if the source connector is stopped.
logger.error("Reprocessing job cancelled because the channel is stopping or stopped.", error);
return true;
}

logger.error("Could not reprocess message " + messageId + " for channel " + channelId + ".", error);
return false;
}

@Override
public int exportMessages(final String channelId, final MessageFilter messageFilter, int pageSize, MessageWriterOptions options) throws MessageExportException, InterruptedException {
final MessageController messageController = this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: Open Integration Engine

package com.mirth.connect.server.controllers;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.contains;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import org.apache.logging.log4j.Logger;
import org.junit.Test;

import com.mirth.connect.donkey.server.channel.ChannelException;

public class DonkeyMessageControllerReprocessTest {

private static final String CHANNEL_ID = "1f2e3d4c-0000-4000-8000-000000000001";

@Test
public void logsAChannelExceptionThatDoesNotStopTheChannelAndMovesOn() {
Logger logger = mock(Logger.class);
ChannelException error = new ChannelException(false);

boolean stop = DonkeyMessageController.logReprocessFailure(logger, CHANNEL_ID, 7L, error);

assertFalse(stop);
verify(logger).error(contains("Could not reprocess message 7 for channel " + CHANNEL_ID), same(error));
}

@Test
public void logsAnUnexpectedErrorAndMovesOn() {
Logger logger = mock(Logger.class);
RuntimeException error = new IllegalStateException("Synthetic dispatch failure");

boolean stop = DonkeyMessageController.logReprocessFailure(logger, CHANNEL_ID, 8L, error);

assertFalse(stop);
verify(logger).error(contains("Could not reprocess message 8 for channel " + CHANNEL_ID), same(error));
}

@Test
public void stopsTheJobWhenTheChannelIsStopping() {
Logger logger = mock(Logger.class);
ChannelException error = new ChannelException(true);

boolean stop = DonkeyMessageController.logReprocessFailure(logger, CHANNEL_ID, 9L, error);

assertTrue(stop);
verify(logger).error(contains("Reprocessing job cancelled"), same(error));
}
}