Files
finlog/finlog_app/fluttery/lib/worker.dart

48 lines
1.2 KiB
Dart

import 'dart:async';
import 'package:fluttery/fluttery.dart';
abstract class Worker extends Service {
Future<T> spawn<T>(
String debugName,
FutureOr<T> Function() task, {
void Function()? preTask,
Duration? timeout, // per-job override
});
/// Currently running jobs.
List<WorkerInfo> getActiveWorkers();
/// All known jobs (active + completed + failed), up to a capped history.
List<WorkerInfo> getAllWorkers();
/// Optional: get a single worker by id.
WorkerInfo? getWorker(String id);
/// Remove completed/failed jobs older than [maxAge] from history.
void purge({Duration maxAge = const Duration(minutes: 30)});
}
enum WorkerStatus { running, completed, failed, timedOut }
class WorkerInfo {
WorkerInfo({
required this.id,
required this.name,
required this.startedAt,
required this.status,
this.endedAt,
this.error,
this.stackTrace,
});
final String id;
final String name;
final DateTime startedAt;
final WorkerStatus status;
final DateTime? endedAt;
final Object? error;
final StackTrace? stackTrace;
Duration get duration => ((endedAt ?? DateTime.now()).difference(startedAt));
}