Skip to main content

jetleaf_scheduling 2.0.0 copy "jetleaf_scheduling: ^2.0.0" to clipboard
jetleaf_scheduling: ^2.0.0 copied to clipboard

Task scheduling and timed execution module for the Jetleaf framework.

example/lib/main.dart

// ignore_for_file: avoid_print

import 'dart:async';

import 'package:jetleaf_core/lang.dart';
import 'package:jetleaf_scheduling/jetleaf_scheduling.dart';

void main() async {
  print('========================================================');
  print('  🍃 Jetleaf Scheduling 2.0.0 Task Engine Showcase');
  print('========================================================\n');

  // 1. Cron Expression Evaluation
  print('[1] Cron Expression Evaluation:');
  final cron = CronExpression('0 0 12 * * *'); // Every day at 12:00:00 PM
  final cronTrigger = CronTrigger.fromExpression(cron, ZoneId.UTC);

  final executionContext = DefaultTaskExecutionContext();
  final nextRun = cronTrigger.nextExecutionTime(executionContext);
  print('Cron: "${cronTrigger.getExpression()}" in Zone "${cronTrigger.getZone()}"');
  print('Next Scheduled Execution: $nextRun\n');

  // 2. Concurrent Task Scheduler
  print('[2] ConcurrentTaskScheduler Execution:');
  final scheduler = ConcurrentTaskScheduler(maxConcurrency: 3);

  final completer = Completer<void>();
  var tickCount = 0;

  final task = await scheduler.scheduleAtFixedRate(
    () {
      tickCount++;
      print('  [Tick $tickCount] Scheduled job executed at: ${DateTime.now().toIso8601String()}');
      if (tickCount >= 3 && !completer.isCompleted) {
        completer.complete();
      }
    },
    const Duration(milliseconds: 100),
    'demoRecurringTask',
  );

  print('Scheduled Task ID: "${task.getName()}" (Initial Total: ${scheduler.getTotalTaskCount()})');
  await completer.future;

  // Cancel task and shutdown scheduler cleanly
  task.cancel();
  await scheduler.shutdown(true);
  print('Task cancelled and scheduler successfully shut down.');

  print('\n========================================================');
  print('  ✅ Jetleaf Scheduling Example executed successfully!');
  print('========================================================');
}
0
likes
160
points
277
downloads

Documentation

Documentation
API reference

Publisher

verified publisherhapnium.com

Weekly Downloads

Task scheduling and timed execution module for the Jetleaf framework.

Homepage
Repository (GitHub)
View/report issues

Topics

#scheduling #tasks #jetleaf #async #timers

License

BSD-2-Clause (license)

Dependencies

jetleaf_core, meta

More

Packages that depend on jetleaf_scheduling