resetJobForRetry method

Future<int> resetJobForRetry(
  1. int id
)

Resets a job to 'PENDING' status for a retry attempt.

This typically clears the last_error and updates last_attempt_at. It does not automatically increment attempts; the job processing logic handles that.

  • id: The ID of the job to reset. Returns the number of rows affected.

Implementation

Future<int> resetJobForRetry(int id) async {
  final job = await getJobById(id);
  if (job == null) return 0;

  // if (job.attempts >= job.maxAttempts) { // Logic for max attempts is handled by the service
  // }

  final ResultSet result = await db.execute(
    "UPDATE background_service_jobs SET status = 'PENDING', last_error = NULL, last_attempt_at = STRFTIME('%Y-%m-%dT%H:%M:%fZ', 'NOW') WHERE id = ?",
    [id],
  );
  return result.length;
}