Skip to content

Commit

Permalink
Fix polling (ECS) command executors fail to run tasks on retry (#1620) (
Browse files Browse the repository at this point in the history
#1632)

Signed-off-by: Naoto Yokoyama <builtinnya@gmail.com>

Co-authored-by: Naoto Yokoyama <builtinnya@gmail.com>
  • Loading branch information
myui and builtinnya committed Sep 3, 2021
1 parent e97e562 commit 93da2fc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Expand Up @@ -51,9 +51,11 @@ public TaskResult run()

boolean doRetry = retry.evaluate();
if (doRetry) {
// Remove command status so that pollable command executors can run tasks on retry
Config nextStateParams = retry.getNextRetryStateParams().remove("commandStatus");
throw TaskExecutionException.ofNextPollingWithCause(ex,
retry.getNextRetryInterval(),
ConfigElement.copyOf(retry.getNextRetryStateParams()));
ConfigElement.copyOf(nextStateParams));
}
else {
throw ex;
Expand Down
@@ -1,6 +1,8 @@
package io.digdag.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

import io.digdag.client.config.Config;
import io.digdag.client.config.ConfigElement;
import io.digdag.client.config.ConfigFactory;
Expand Down Expand Up @@ -102,6 +104,37 @@ public TaskResult runTask()
}
}

@Test
public void verifyNonPollingRuntimeExceptionRemovesCommandStatusOnRetry()
throws Exception
{
config.set("_retry", 10);

ObjectNode commandStatus = new ObjectMapper().createObjectNode().put("foo", "bar");
state.set("commandStatus", commandStatus);

RuntimeException ex = new RuntimeException("Command failed");

BaseOperator op = new BaseOperator(newContext(temporaryFolder.getRoot().toPath(), request))
{
@Override
public TaskResult runTask()
{
throw ex;
}
};

try {
op.run();
fail();
}
catch (TaskExecutionException e) {
assertThat(e.isError(), is(true));
assertThat(e.getCause(), is(ex));
assertThat(e.getStateParams(configFactory).get().has("commandStatus"), is(false));
}
}

private OperatorContext newContext(final Path projectPath, final TaskRequest taskRequest)
{
return new OperatorContext()
Expand Down

0 comments on commit 93da2fc

Please sign in to comment.