getJobsByStatus method
Future<List<BackgroundJob> >
getJobsByStatus(
- BackgroundJobStatus status, {
- int? limit,
- int? offset,
- String orderByCreation = 'ASC',
Fetches jobs by their status.
status
: The BackgroundJobStatus to filter by.limit
: Optional limit on the number of jobs to return.offset
: Optional offset for pagination.orderByCreation
: Optional sort order bycreated_at
('ASC' or 'DESC').
Implementation
Future<List<BackgroundJob>> getJobsByStatus(
BackgroundJobStatus status, {
int? limit,
int? offset,
String orderByCreation = 'ASC', // ASC for older first, DESC for newer first
}) async {
String query =
"SELECT * FROM background_service_jobs WHERE status = ? ORDER BY created_at $orderByCreation";
final params = <Object?>[status.name.toUpperCase()];
if (limit != null) {
query += " LIMIT ?";
params.add(limit);
if (offset != null) {
query += " OFFSET ?";
params.add(offset);
}
}
final List<Map<String, Object?>> results = await db.getAll(query, params);
return results.map((map) => BackgroundJob.fromMap(map)).toList();
}