BackgroundJobManager class
Manages interactions with the background_service_jobs
table.
This class provides methods to query, update, and delete background jobs.
It requires an SqliteConnection
to perform database operations.
Constructors
- BackgroundJobManager.new({required SqliteConnection db})
- Creates a new instance of BackgroundJobManager.
Properties
- db → SqliteConnection
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
deleteJob(
int id) → Future< int> - Deletes a specific job by its ID.
-
deleteJobsByPriority(
int priority, {DateTime? olderThan}) → Future< int> -
deleteJobsByStatus(
BackgroundJobStatus status, {DateTime? olderThan}) → Future< int> - Deletes jobs by their status, optionally older than a specific date.
-
enqueueJob(
{required String jobKey, Map< String, dynamic> ? payload, int priority = 1, int maxAttempts = 3}) → Future<void> - Enqueues a new job.
-
getAllJobs(
{int? limit, int? offset}) → Future< List< BackgroundJob> > - Fetches all jobs, with optional pagination.
-
getJobById(
int id) → Future< BackgroundJob?> - Fetches a single job by its ID.
-
getJobCountByStatus(
BackgroundJobStatus status) → Future< int> - Gets the count of jobs with a specific status.
-
getJobsByJobKey(
String jobKey, {BackgroundJobStatus? status, int? limit, int? offset}) → Future< List< BackgroundJob> > -
Fetches jobs by their
jobKey
. -
getJobsByStatus(
BackgroundJobStatus status, {int? limit, int? offset, String orderByCreation = 'ASC'}) → Future< List< BackgroundJob> > - Fetches jobs by their status.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
resetJobForRetry(
int id) → Future< int> - Resets a job to 'PENDING' status for a retry attempt.
-
toString(
) → String -
A string representation of this object.
inherited
-
updateJobStatus(
int id, BackgroundJobStatus newStatus, {String? lastError}) → Future< int> - Updates the status of a specific job.
-
updateJobStatusByJobKey(
String jobKey, BackgroundJobStatus newStatus, {required String message}) → Future< int> - Updates the status and message for all jobs with a specific jobKey.
-
watchAllJobs(
) → Stream< List< BackgroundJob> > -
Watches all jobs in the database, emitting a new list whenever the
background_service_jobs
table changes.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited