BREAKING CHANGE(taskbuffer): Introduce constraint-based concurrency with TaskConstraintGroup and TaskManager integration; remove legacy TaskRunner and several Task APIs (breaking); add typed Task.data and update exports and tests.
This commit is contained in:
@@ -1,20 +1,42 @@
|
||||
# Taskbuffer Hints
|
||||
|
||||
## Task Constraint System (v5.0.0+) — Breaking Changes
|
||||
- **`TaskRunner` removed** — replaced by `TaskManager` + `TaskConstraintGroup`
|
||||
- **`blockingTasks` removed** from `Task` — use `TaskConstraintGroup` with `maxConcurrent: 1`
|
||||
- **`execDelay` removed** from `Task` — use `TaskConstraintGroup` with `cooldownMs`
|
||||
- **`finished` promise removed** from `Task` — no longer needed
|
||||
- **`Task` generic signature**: `Task<T, TSteps, TData>` (3rd param added for typed data)
|
||||
|
||||
### Task.data
|
||||
- `Task` constructor accepts optional `data?: TData` (defaults to `{}`)
|
||||
- Typed data bag accessible as `task.data`
|
||||
|
||||
### TaskConstraintGroup
|
||||
- `new TaskConstraintGroup<TData>({ name, constraintKeyForTask, maxConcurrent?, cooldownMs? })`
|
||||
- `constraintKeyForTask(task)` returns a string key (constraint applies) or `null` (skip)
|
||||
- `maxConcurrent` (default: `Infinity`) — max concurrent tasks per key
|
||||
- `cooldownMs` (default: `0`) — minimum ms gap between completions per key
|
||||
- Methods: `canRun(key)`, `acquireSlot(key)`, `releaseSlot(key)`, `getCooldownRemaining(key)`, `getRunningCount(key)`, `reset()`
|
||||
|
||||
### TaskManager Constraint Integration
|
||||
- `manager.addConstraintGroup(group)` / `manager.removeConstraintGroup(name)`
|
||||
- `triggerTaskByName()`, `triggerTask()`, `addExecuteRemoveTask()`, cron callbacks all route through `triggerTaskConstrained()`
|
||||
- `triggerTaskConstrained(task, input?)` — evaluates constraints, queues if blocked, drains after completion
|
||||
- Cooldown-blocked entries auto-drain via timer
|
||||
|
||||
### Exported from index.ts
|
||||
- `TaskConstraintGroup` class
|
||||
- `ITaskConstraintGroupOptions` type
|
||||
|
||||
## Error Handling (v3.6.0+)
|
||||
- `Task` now has `catchErrors` constructor option (default: `false`)
|
||||
- Default behavior: `trigger()` rejects when taskFunction throws (breaking change from pre-3.6)
|
||||
- Set `catchErrors: true` to swallow errors (old behavior) - returns `undefined` on error
|
||||
- Error state tracked via `lastError?: Error`, `errorCount: number`, `clearError()`
|
||||
- `getMetadata()` status uses all four values: `'idle'` | `'running'` | `'completed'` | `'failed'`
|
||||
- All peripheral classes (Taskchain, Taskparallel, TaskRunner, BufferRunner, TaskDebounced, TaskManager) have proper error propagation/handling
|
||||
- All peripheral classes (Taskchain, Taskparallel, BufferRunner, TaskDebounced, TaskManager) have proper error propagation/handling
|
||||
- `console.log` calls replaced with `logger.log()` throughout
|
||||
|
||||
## Breaking API Rename (TaskRunner)
|
||||
- `maxParrallelJobs` → `maxParallelJobs`
|
||||
- `qeuedTasks` → `queuedTasks`
|
||||
- JSDoc typos fixed: "qeue" → "queue", "wether" → "whether", "loose" → "lose"
|
||||
- The `setMaxParallelJobs()` parameter also renamed from `maxParrallelJobsArg` to `maxParallelJobsArg`
|
||||
|
||||
## Error Context Improvements
|
||||
- **TaskChain**: Errors now wrap the original with context: chain name, failing task name, and task index. Original error preserved via `.cause`
|
||||
- **BufferRunner**: When `catchErrors: false`, buffered task errors now reject the trigger promise (via `CycleCounter.informOfCycleError`) instead of silently resolving with `undefined`
|
||||
|
||||
Reference in New Issue
Block a user