ScheduledTask.fromConfig constructor
Creates a scheduled task from a configuration map
Implementation
factory ScheduledTask.fromConfig(Map<String, dynamic> config) {
final jobName = config['job'] as String;
final job = SchedulerJobRegistry.resolve(jobName, config);
if (job == null) {
throw Exception('Job "$jobName" not found in TaskRunner.');
}
if (config['cron'] != null) {
Khadem.logger.warning(
'⚠️ Cron expressions are not supported. Task "${config['name']}" will be ignored.',
);
throw ArgumentError('Cron is not supported in this version.');
}
if (config['interval'] == null) {
throw ArgumentError(
'Missing "interval" for scheduled task "${config['name']}"',
);
}
return ScheduledTask(
name: config['name'] as String,
interval: Duration(seconds: config['interval'] as int),
timeZone: config['timezone']?.toString() ?? 'UTC',
job: job,
retryOnFail: config['retryOnFail'] as bool? ?? false,
runOnce: config['runOnce'] as bool? ?? false,
maxRetries: config['maxRetries'] as int? ?? 3,
);
}