feat: schedule due processing from next dueAt instead of polling

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
0264408
2026-09-20 16:54:13 +08:00
co-authored by Cursor
parent 8d08a2840b
commit 02557a9b86
15 changed files with 183 additions and 12 deletions
@@ -11,6 +11,7 @@ import com.jetlumen.ordo.api.runtime.ProcessContext;
import com.jetlumen.ordo.api.runtime.ProcessEvent;
import com.jetlumen.ordo.api.runtime.ProcessInstance;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
@@ -40,6 +41,9 @@ public interface OrdoEngine {
/** Claims and processes up to {@code limit} overdue pending tasks. {@code limit} must be positive. */
int processDue(int limit);
/** Earliest {@code dueAt} among pending tasks, or empty if none are scheduled. */
Optional<Instant> nextDueAt();
default ProcessInstance withdraw(String instanceId, String actor) {
return withdraw(instanceId, actor, null);
}
@@ -43,6 +43,9 @@ public interface ApprovalTaskRepository {
List<ApprovalTask> findDuePending(Instant now, int limit);
/** Earliest {@code dueAt} among pending tasks, or empty if none are scheduled. */
Optional<Instant> findNextDueAt();
boolean claimIfDue(String taskId, String expectedAssignee, Instant now);
/** Paginated, filterable query; results are ordered newest-first (created_at desc). */