storagehub/src/main/java/org/gcube/data/access/storagehub/services/admin/ScriptStatus.java

109 lines
2.3 KiB
Java
Raw Normal View History

2022-12-15 12:08:39 +01:00
package org.gcube.data.access.storagehub.services.admin;
2022-12-15 15:24:30 +01:00
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
2022-12-15 12:08:39 +01:00
public class ScriptStatus {
enum Status {
Running, Success, Failed
}
2022-12-15 15:24:30 +01:00
private static final DateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy HH:mm:ss:SSS Z") ;
2022-12-15 12:08:39 +01:00
private Status status;
private String errorMessage;
2024-04-05 21:11:04 +02:00
private String result;
2022-12-15 12:08:39 +01:00
private long start;
2022-12-15 15:24:30 +01:00
private long finished = -1;
2022-12-15 12:08:39 +01:00
private String runningId;
2022-12-15 15:24:30 +01:00
private String executionServer;
public ScriptStatus(String runningId, String resultPath, String executionServer) {
2022-12-15 12:08:39 +01:00
super();
this.status = Status.Running;
this.start = System.currentTimeMillis();
2022-12-15 15:24:30 +01:00
this.runningId = runningId;
2024-04-05 21:11:04 +02:00
this.result = resultPath;
this.executionServer = executionServer;
}
public ScriptStatus(String runningId, String executionServer) {
super();
this.status = Status.Running;
this.start = System.currentTimeMillis();
this.runningId = runningId;
2022-12-15 15:24:30 +01:00
this.executionServer = executionServer;
2022-12-15 12:08:39 +01:00
}
public void setFailed(String error) {
this.status = Status.Failed;
this.errorMessage = error;
2022-12-15 15:24:30 +01:00
this.finished = System.currentTimeMillis();
2022-12-15 12:08:39 +01:00
}
2022-12-15 15:24:30 +01:00
public void setSuccess() {
2022-12-15 12:08:39 +01:00
this.status = Status.Success;
2022-12-15 15:24:30 +01:00
this.finished = System.currentTimeMillis();
2022-12-15 12:08:39 +01:00
}
2024-04-05 21:11:04 +02:00
public void setSuccess(String result) {
this.status = Status.Success;
this.finished = System.currentTimeMillis();
this.result = result;
}
2022-12-15 12:08:39 +01:00
public Status getStatus() {
return status;
}
public String getErrorMessage() {
return errorMessage;
}
2022-12-15 15:24:30 +01:00
public String getStartDate() {
Date date = new Date(this.start);
return dateFormat.format(date);
}
public long getDurationInMillis() {
long toUse = finished;
if (finished < 0)
toUse = System.currentTimeMillis();
return toUse-start;
}
public String getHumanReadableDuration() {
long toUse = finished;
if (finished < 0)
toUse = System.currentTimeMillis();
2022-12-15 15:36:12 +01:00
long duration = toUse - this.start;
long minutes = (duration/1000)/60;
long seconds = (duration/1000)%60;
2022-12-15 15:24:30 +01:00
return String.format("%d minutes %d seconds", minutes, seconds);
2022-12-15 12:08:39 +01:00
}
2024-04-05 21:11:04 +02:00
public String getResult() {
return result;
2022-12-15 12:08:39 +01:00
}
public String getRunningId() {
return runningId;
}
2022-12-15 15:24:30 +01:00
public String getExecutionServer() {
return executionServer;
}
2022-12-15 12:08:39 +01:00
}