scheduleJob method

void scheduleJob({
  1. required String id,
  2. required String url,
  3. required int interval,
  4. required Map<String, String> selectors,
  5. Map<String, String?>? attributes,
  6. void onResult(
    1. List<Map<String, String>>
    )?,
  7. void onError(
    1. Exception
    )?,
})

Schedules a new scraping job

id is the unique identifier for the job url is the URL to scrape interval is the interval between runs in milliseconds selectors is a map of field names to CSS selectors attributes is a map of field names to attributes to extract (optional) onResult is a callback for handling the results onError is a callback for handling errors

Implementation

void scheduleJob({
  required String id,
  required String url,
  required int interval,
  required Map<String, String> selectors,
  Map<String, String?>? attributes,
  void Function(List<Map<String, String>>)? onResult,
  void Function(Exception)? onError,
}) {
  // Cancel any existing job with the same ID
  cancelJob(id);

  // Create a new job
  final job = ScrapingJob(
    id: id,
    url: url,
    interval: interval,
    selectors: selectors,
    attributes: attributes,
    lastRun: DateTime.now().millisecondsSinceEpoch,
  );

  // Save the job
  _saveJob(job);

  // Schedule the job
  _scheduleJob(job, onResult, onError);
}