com.weaverplatform.queue.StatusReport Maven / Gradle / Ivy
package com.weaverplatform.queue;
import com.google.gson.Gson;
import cool.graph.cuid.Cuid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
/**
* @author bastbijl, Sysunite 2018
*/
public class StatusReport {
static Logger logger = LoggerFactory.getLogger(StatusReport.class);
public static Gson gson = new Gson();
public String id;
public Boolean done;
public Boolean pending;
public Boolean errored;
public String message;
public List log;
public String fileId;
public int progress;
public int scale;
public StatusReport() {
this.id = Cuid.createCuid().substring(20, 25);
}
public StatusReport(boolean done) {
this.done = done;
}
public StatusReport(boolean done, String message) {
this.done = done;
setMessage(message);
}
public StatusReport setDone(boolean done) {
this.done = done;
return this;
}
public StatusReport setPending(boolean pending) {
this.pending = pending;
return this;
}
public StatusReport setErrored(boolean errored) {
this.errored = errored;
return this;
}
public StatusReport setMessage(String message) {
this.message = message;
logger.info("Set message on job: "+message);
return this;
}
public StatusReport addLog(String line) {
if(log == null) {
log = new ArrayList<>();
}
log.add(line);
return this;
}
public StatusReport setFileId(String fileId) {
this.fileId = fileId;
return this;
}
public StatusReport setProgress(int progress) {
this.progress = progress;
return this;
}
public StatusReport setScale(int scale) {
this.scale = scale;
return this;
}
public String getId() {
return id;
}
public String toString() {
return gson.toJson(this);
}
}