scheduleJob method
void
scheduleJob({})
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);
}