Skip to content

Commit

Permalink
Recreate new TaskInstance Working Directory when exist in worker
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanwenjun committed Dec 25, 2023
1 parent 9212531 commit c8b77bc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ protected void beforeExecute() {
taskExecutionContext.setTenantCode(tenant);
log.info("TenantCode: {} check successfully", taskExecutionContext.getTenantCode());

TaskExecutionContextUtils.createProcessLocalPathIfAbsent(taskExecutionContext);
TaskExecutionContextUtils.createTaskInstanceWorkingDirectory(taskExecutionContext);
log.info("WorkflowInstanceExecDir: {} check successfully", taskExecutionContext.getExecutePath());

TaskChannel taskChannel =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,29 @@ public static String getOrCreateTenant(WorkerConfig workerConfig, TaskExecutionC
}
}

public static void createProcessLocalPathIfAbsent(TaskExecutionContext taskExecutionContext) throws TaskException {
public static void createTaskInstanceWorkingDirectory(TaskExecutionContext taskExecutionContext) throws TaskException {
// local execute path
String taskInstanceWorkingDirectory = FileUtils.getProcessExecDir(
taskExecutionContext.getTenantCode(),
taskExecutionContext.getProjectCode(),
taskExecutionContext.getProcessDefineCode(),
taskExecutionContext.getProcessDefineVersion(),
taskExecutionContext.getProcessInstanceId(),
taskExecutionContext.getTaskInstanceId());
try {
// local execute path
String execLocalPath = FileUtils.getProcessExecDir(
taskExecutionContext.getTenantCode(),
taskExecutionContext.getProjectCode(),
taskExecutionContext.getProcessDefineCode(),
taskExecutionContext.getProcessDefineVersion(),
taskExecutionContext.getProcessInstanceId(),
taskExecutionContext.getTaskInstanceId());
taskExecutionContext.setExecutePath(execLocalPath);
taskExecutionContext.setAppInfoPath(FileUtils.getAppInfoPath(execLocalPath));
Path executePath = Paths.get(taskExecutionContext.getExecutePath());
FileUtils.createDirectoryIfNotPresent(executePath);
Path path = Paths.get(taskInstanceWorkingDirectory);
if (Files.deleteIfExists(path)) {
log.warn("The TaskInstance WorkingDirectory: {} is exist, will recreate again",
taskInstanceWorkingDirectory);
}
Files.createDirectories(path);
taskExecutionContext.setExecutePath(taskInstanceWorkingDirectory);

taskExecutionContext.setExecutePath(taskInstanceWorkingDirectory);
taskExecutionContext.setAppInfoPath(FileUtils.getAppInfoPath(taskInstanceWorkingDirectory));
} catch (Throwable ex) {
throw new TaskException("Cannot create process execute dir", ex);
throw new TaskException(
"Cannot create TaskInstance WorkingDirectory: " + taskInstanceWorkingDirectory + " failed", ex);
}
}

Expand Down

0 comments on commit c8b77bc

Please sign in to comment.