-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/main/java/io/orkes/samples/workers/FailNTimesWorker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.orkes.samples.workers; | ||
|
||
import com.netflix.conductor.client.worker.Worker; | ||
import com.netflix.conductor.common.metadata.tasks.Task; | ||
import com.netflix.conductor.common.metadata.tasks.TaskResult; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.Instant; | ||
import java.util.Map; | ||
|
||
@Component | ||
public class FailNTimesWorker implements Worker { | ||
@Override | ||
public String getTaskDefName() { | ||
return "fail_n_times"; | ||
} | ||
|
||
@Override | ||
public TaskResult execute(Task task) { | ||
TaskResult result = new TaskResult(task); | ||
if(!task.isRetried()) { | ||
result.addOutputData("initialStartTime", Instant.ofEpochMilli(task.getStartTime()).toString()); | ||
result.addOutputData("initialTaskExecutionTime", Instant.now().toString()); | ||
result.addOutputData("initialScheduledTime", Instant.ofEpochMilli(task.getScheduledTime()).toString()); | ||
} | ||
int timesToFail = getIntValue("timesToFail", 1, task.getInputData()); | ||
int failedCount = getIntValue("failedCount", 0, task.getOutputData()); | ||
if(failedCount >= timesToFail) { | ||
result.addOutputData("outputVal", "This task completed failing for configured number of times - " + timesToFail); | ||
result.setStatus(TaskResult.Status.COMPLETED); | ||
} | ||
result.addOutputData("failedCount", ++failedCount); | ||
result.addOutputData("outputVal", "This task fails (for testing) for " + timesToFail + " times"); | ||
result.setStatus(TaskResult.Status.FAILED); | ||
return result; | ||
} | ||
|
||
private static int getIntValue(String paramName, int defaultValue, Map<String, Object> data) { | ||
return ((Number) (data.getOrDefault(paramName, defaultValue))).intValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
conductor.server.url=https://play.orkes.io/api | ||
|
||
conductor.security.client.key-id=b274eb68-0630-4d82-b8ff-266d3f137344 | ||
conductor.security.client.secret=yRpxiEOa4tFF9 iKlNFXyUf9V437KbuUQSYvvHW5GuSf7LL8o | ||
conductor.security.client.key-id=_CHANGE_ME_ | ||
conductor.security.client.secret=_CHANGE_ME_ |