Skip to content

Commit

Permalink
Merge pull request #13 from mytang0/1.0.0-beta
Browse files Browse the repository at this point in the history
1.0.0 beta
  • Loading branch information
mytang0 authored Feb 6, 2025
2 parents 78a158a + d89c0e3 commit a997aca
Show file tree
Hide file tree
Showing 35 changed files with 1,127 additions and 427 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class TaskDef implements Serializable {

private static final long serialVersionUID = -8797791731692389319L;

public static final TaskDef MATCHED = new TaskDef();

@NotBlank
private String type;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package xyz.mytang0.brook.common.metadata.instance;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import xyz.mytang0.brook.common.holder.UserHolder;
import xyz.mytang0.brook.common.metadata.definition.FlowDef;
import xyz.mytang0.brook.common.metadata.definition.TaskDef;
import xyz.mytang0.brook.common.metadata.enums.FlowStatus;
import xyz.mytang0.brook.common.metadata.extension.Extension;
import xyz.mytang0.brook.common.metadata.model.User;
import xyz.mytang0.brook.common.utils.IDUtils;
import xyz.mytang0.brook.common.utils.JsonUtils;
import xyz.mytang0.brook.common.utils.StringUtils;
import xyz.mytang0.brook.common.utils.TimeUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

@Data
public class FlowInstance implements Serializable {
Expand Down Expand Up @@ -110,6 +114,30 @@ public boolean hasParent() {
return StringUtils.isNotBlank(parentFlowId);
}

public FlowInstance deepCopy() {
FlowInstance newInstance = JsonUtils.readValue(
JsonUtils.toJsonString(this),
FlowInstance.class);
newInstance.setFlowDef(flowDef);

Optional.ofNullable(this.getTaskInstances())
.ifPresent(taskInstances -> {
Map<String, TaskDef> taskDefMap =
this.getTaskInstances().stream()
.collect(Collectors.toMap(
TaskInstance::getTaskId,
TaskInstance::getTaskDef));

newInstance.getTaskInstances().forEach(taskInstance -> {
if (taskInstance.getTaskDef() == null) {
taskInstance.setTaskDef(
taskDefMap.get(taskInstance.getTaskId()));
}
});
});
return newInstance;
}

public static FlowInstance create(FlowDef flowDef) {
FlowInstance flowInstance = new FlowInstance();
flowInstance.setFlowId(IDUtils.generator(flowDef));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,34 @@ public TaskInstance copy() {
copy.setStatus(status);
copy.setReasonForNotCompleting(reasonForNotCompleting);
copy.setInput(input);
copy.setOutput(output);
copy.setSubFlowId(subFlowId);
copy.setParentTaskId(parentTaskId);
copy.setHangTaskId(hangTaskId);
copy.setProgress(progress);
copy.setLink(link);
copy.setExtension(extension);
copy.setExecuted(executed);
copy.setHanging(hanging);
copy.setScheduledTime(scheduledTime);
copy.setStartTime(startTime);
copy.setLastUpdated(lastUpdated);
copy.setEndTime(endTime);
copy.setStartDelayMs(startDelayMs);
copy.setRetryTime(retryTime);
copy.setRetryCount(retryCount);

return copy;
}

public TaskInstance deepCopy() {
TaskInstance newInstance = JsonUtils.readValue(
JsonUtils.toJsonString(this),
TaskInstance.class);
newInstance.setTaskDef(taskDef);
return newInstance;
}

@JsonIgnore
public boolean isRetryable() {
return getStatus().isRetryable()
Expand Down Expand Up @@ -150,6 +174,13 @@ public String getExtension(String key, String defaultValue) {
.orElse(defaultValue);
}

public void mergeExtension(Extension pending) {
if (pending != null && !pending.isEmpty()) {
initExtension();
extension.putAll(pending);
}
}

public void setExtension(String key, String value) {
initExtension();
extension.put(key, value);
Expand Down Expand Up @@ -179,8 +210,16 @@ public static TaskInstance create(TaskDef taskDef) {
taskInstance.setScheduledTime(TimeUtils.currentTimeMillis());
Optional.ofNullable(taskDef.getControlDef())
.ifPresent(controlDef -> {
taskInstance.setStartDelayMs(controlDef.getStartDelayMs());
});
long startDelayMs
= controlDef.getStartDelayMs();
if (startDelayMs > 0) {
taskInstance.setStartDelayMs(startDelayMs);
taskInstance.setScheduledTime(
taskInstance.getScheduledTime()
+ startDelayMs);
}
}
);
return taskInstance;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package xyz.mytang0.brook.common.metadata.model;

import xyz.mytang0.brook.common.metadata.enums.TaskStatus;
import lombok.Data;
import xyz.mytang0.brook.common.metadata.enums.TaskStatus;
import xyz.mytang0.brook.common.metadata.extension.Extension;

import javax.annotation.Nonnull;
import javax.validation.constraints.NotBlank;
Expand All @@ -28,4 +29,6 @@ public class TaskResult implements Serializable {
private Object output;

private Integer progress;

private Extension extension;
}
Loading

0 comments on commit a997aca

Please sign in to comment.