package io.trygvis.queue; import java.util.Date; import java.util.List; public class Task { public final long id; public final Long parent; public final String queue; public final Date scheduled; public final Date lastRun; public final int runCount; public final Date completed; public final List arguments; public Task(long id, Long parent, String queue, Date scheduled, Date lastRun, int runCount, Date completed, List arguments) { this.id = id; this.parent = parent; this.queue = queue; this.scheduled = scheduled; this.lastRun = lastRun; this.runCount = runCount; this.completed = completed; this.arguments = arguments; } public Task registerRun() { return new Task(id, parent, queue, scheduled, new Date(), runCount + 1, completed, arguments); } public Task registerComplete(Date completed) { return new Task(id, parent, queue, scheduled, lastRun, runCount, completed, arguments); } public String toString() { return "Task{" + "id=" + id + ", parent=" + parent + ", queue=" + queue + ", scheduled=" + scheduled + ", lastRun=" + lastRun + ", runCount=" + runCount + ", completed=" + completed + ", arguments='" + arguments + '\'' + '}'; } public boolean isDone() { return completed != null; } }