From 0a0b01664cf620f983549999b24a7740594a57d4 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 30 Apr 2013 07:12:56 +0200 Subject: o Initial import. --- src/main/java/io/trygvis/queue/Task.java | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 src/main/java/io/trygvis/queue/Task.java (limited to 'src/main/java/io/trygvis/queue/Task.java') diff --git a/src/main/java/io/trygvis/queue/Task.java b/src/main/java/io/trygvis/queue/Task.java new file mode 100755 index 0000000..2a061bd --- /dev/null +++ b/src/main/java/io/trygvis/queue/Task.java @@ -0,0 +1,60 @@ +package io.trygvis.queue; + +import java.util.*; + +import static java.util.Collections.unmodifiableList; + +/** + * TODO: next run on failures. A default strategy from the queue, let the task be able to re-schedule itself. + */ +public class Task { + + public final long id; + + public final String queue; + + public final Date scheduled; + + public final Date lastRun; + + public final int runCount; + + public final Date completed; + + public final List arguments; + + Task(long id, String queue, Date scheduled, Date lastRun, int runCount, Date completed, List arguments) { + this.id = id; + this.queue = queue; + this.scheduled = scheduled; + this.lastRun = lastRun; + this.runCount = runCount; + this.completed = completed; + + this.arguments = unmodifiableList(new ArrayList<>(arguments)); + } + + public Task registerRun() { + return new Task(id, queue, scheduled, new Date(), runCount + 1, completed, arguments); + } + + public Task registerComplete(Date completed) { + return new Task(id, queue, scheduled, lastRun, runCount, new Date(), arguments); + } + + public String toString() { + return "Task{" + + "id=" + id + + ", queue=" + queue + + ", scheduled=" + scheduled + + ", lastRun=" + lastRun + + ", runCount=" + runCount + + ", completed=" + completed + + ", arguments='" + arguments + '\'' + + '}'; + } + + public boolean isDone() { + return completed != null; + } +} -- cgit v1.2.3