tasks method

List<TaskInfo> tasks({
  1. TaskState? state,
  2. String? name,
  3. String? queue,
  4. String? worker,
  5. int limit = 200,
  6. int offset = 0,
})

Tasks, most-recently-updated first, optionally filtered.

Implementation

List<TaskInfo> tasks({
  TaskState? state,
  String? name,
  String? queue,
  String? worker,
  int limit = 200,
  int offset = 0,
}) {
  final all = _tasks.values
      .where((t) => state == null || t.state == state)
      .where((t) => name == null || t.name == name)
      .where((t) => queue == null || t.queue == queue)
      .where((t) => worker == null || t.workerId == worker)
      .toList()
    ..sort((a, b) => b.updatedAt.compareTo(a.updatedAt));
  if (offset >= all.length) return const [];
  return all.sublist(offset, (offset + limit).clamp(0, all.length));
}