ruanwenjun commented on pull request #5156:
URL:
https://github.com/apache/incubator-dolphinscheduler/pull/5156#issuecomment-808117806
> I suggest to change it like this
>
> ```
> LogClientService logClient = null;
>
>
>
> List<TaskInstance> taskInstanceList =
findValidTaskListByProcessId(processInstanceId);
>
> if (CollectionUtils.isEmpty(taskInstanceList)) {
> return;
> }
>
> try {
> logClient = new LogClientService();
> for (TaskInstance taskInstance : taskInstanceList) {
> String taskLogPath = taskInstance.getLogPath();
> if (StringUtils.isEmpty(taskInstance.getHost())) {
> continue;
> }
> int port = Constants.RPC_PORT;
> String ip = "";
> try {
> ip = Host.of(taskInstance.getHost()).getIp();
> } catch (Exception e) {
> // compatible old version
> ip = taskInstance.getHost();
> }
>
> // remove task log from loggerserver
> logClient.removeTaskLog(ip, port, taskLogPath);
> }
> } finally {
>
> if (logClient != null) {
> logClient.close();
> }
>
> }
> }
> ```
Agree. By the way, if the LogClientService implements AutoCloseable, we can
even use try with resource
```
try(LogClientService clientService = new ClientService){
}catch(Exception){
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]