feat:(unify): 新增项目初始化功能
This commit is contained in:
parent
54632b5f55
commit
6810a46ec5
@ -13,6 +13,7 @@ import com.aizuda.snailjob.server.web.model.response.SaveFileRequestVO;
|
||||
import com.aizuda.snailjob.server.web.model.response.ViewFileResponseVO;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.File;
|
||||
@ -29,6 +30,7 @@ import java.util.stream.Stream;
|
||||
@RestController
|
||||
@RequestMapping("/file")
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class FileViewerController {
|
||||
private static final String workdir = System.getProperty("user.dir") + File.separator + "sj-python-workspace" + File.separator;
|
||||
|
||||
@ -50,17 +52,15 @@ public class FileViewerController {
|
||||
}
|
||||
return fileVO;
|
||||
})
|
||||
.toList().stream().sorted(new Comparator<FileVO>() {
|
||||
@Override
|
||||
public int compare(FileVO o1, FileVO o2) {
|
||||
.toList().stream().sorted((o1, o2) -> {
|
||||
if (o2.getFileType().compareTo(o1.getFileType()) == 0) {
|
||||
return o1.getFileName().compareTo(o2.getFileName());
|
||||
}
|
||||
return o2.getFileType().compareTo(o1.getFileType());
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
} catch (IOException e) {
|
||||
throw new SnailJobServerException("获取文件列表失败", e);
|
||||
// log.error("获取文件列表失败", e);
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ public class FileViewerController {
|
||||
|
||||
File downloadFile = HttpUtil.downloadFileFromUrl(initProjectVO.getProjectUrl(), mkdir);
|
||||
ZipUtil.unzip(downloadFile, mkdir);
|
||||
downloadFile.deleteOnExit();
|
||||
FileUtil.del(downloadFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -29,14 +29,20 @@ public class PythonServiceImpl implements PythonService {
|
||||
|
||||
@Override
|
||||
public boolean runPython(RunPythonRequestVO requestVO) {
|
||||
if (getStatus()) {
|
||||
throw new SnailJobServerException("客户端已经启动");
|
||||
}
|
||||
new Thread(() -> execPython(requestVO)).start();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stopPython() {
|
||||
if (!getStatus()) {
|
||||
throw new SnailJobServerException("客户端已经关闭");
|
||||
}
|
||||
// todo 端口看怎么获取
|
||||
killProcessOnPort(17889);
|
||||
killProcessOnPort(17890);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -44,7 +50,7 @@ public class PythonServiceImpl implements PythonService {
|
||||
public Boolean getStatus() {
|
||||
try {
|
||||
// 构造 lsof 命令
|
||||
ProcessBuilder lsofBuilder = new ProcessBuilder("lsof", "-t", "-i:" + 17889);
|
||||
ProcessBuilder lsofBuilder = new ProcessBuilder("lsof", "-t", "-i:" + 17890);
|
||||
Process lsofProcess = lsofBuilder.start();
|
||||
|
||||
// 获取 lsof 输出 (进程 ID)
|
||||
|
Loading…
Reference in New Issue
Block a user