Skip to content

Commit

Permalink
fix issue with incorrect parsing of task status
Browse files Browse the repository at this point in the history
  • Loading branch information
wsorenson committed Dec 28, 2015
1 parent 9a9646f commit 2e31649
Showing 1 changed file with 14 additions and 2 deletions.
Expand Up @@ -7,6 +7,8 @@
import java.util.Map;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.time.DurationFormatUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -65,6 +67,8 @@ public class SingularityMailer implements Managed {
private final Joiner adminJoiner;
private final MailTemplateHelpers mailTemplateHelpers;

private final static Pattern TASK_STATUS_BY_PATTERN = Pattern.compile("(\\w+) by \\w+");

@Inject
public SingularityMailer(
SingularitySmtpSender smtpSender,
Expand Down Expand Up @@ -155,13 +159,21 @@ private void populateTaskEmailProperties(Map<String, Object> templateProperties,
templateProperties.put("taskRan", mailTemplateHelpers.didTaskRun(taskHistory));
}

private Optional<TaskCleanupType> getTaskCleanupTypefromSingularityTaskHistoryUpdate(SingularityTaskHistoryUpdate taskHistoryUpdate) {
private static Optional<TaskCleanupType> getTaskCleanupTypefromSingularityTaskHistoryUpdate(SingularityTaskHistoryUpdate taskHistoryUpdate) {
if (!taskHistoryUpdate.getStatusMessage().isPresent()) {
return Optional.absent();
}

String taskCleanupTypeMsg = taskHistoryUpdate.getStatusMessage().get();

Matcher matcher = TASK_STATUS_BY_PATTERN.matcher(taskCleanupTypeMsg);

if (matcher.find()) {
taskCleanupTypeMsg = matcher.group(1);
}

try {
return Optional.of(TaskCleanupType.valueOf(taskHistoryUpdate.getStatusMessage().get()));
return Optional.of(TaskCleanupType.valueOf(taskCleanupTypeMsg.toUpperCase()));
} catch (IllegalArgumentException iae) {
LOG.warn("Couldn't parse TaskCleanupType from update {}", taskHistoryUpdate);
return Optional.absent();
Expand Down

0 comments on commit 2e31649

Please sign in to comment.