From 524cc3900a5a8ea5f2a6d1510b106c8d647aa54e Mon Sep 17 00:00:00 2001 From: Ricardo Romero Date: Sun, 16 Jun 2024 22:12:03 +0200 Subject: [PATCH] Created example with scheduler --- .../.vscode/launch.json | 42 +++++++++++++++++++ examples/dartness_simple/lib/src/app.dart | 4 ++ examples/dartness_simple/lib/src/app.g.dart | 2 + .../lib/src/schedulers/example_scheduler.dart | 11 +++++ .../src/schedulers/example_scheduler.g.dart | 14 +++++++ examples/dartness_simple/pubspec.yaml | 8 ++-- 6 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 examples/dartness_flutter_melos/.vscode/launch.json create mode 100644 examples/dartness_simple/lib/src/schedulers/example_scheduler.dart create mode 100644 examples/dartness_simple/lib/src/schedulers/example_scheduler.g.dart diff --git a/examples/dartness_flutter_melos/.vscode/launch.json b/examples/dartness_flutter_melos/.vscode/launch.json new file mode 100644 index 00000000..a9c1b03c --- /dev/null +++ b/examples/dartness_flutter_melos/.vscode/launch.json @@ -0,0 +1,42 @@ +{ + // Use IntelliSense para saber los atributos posibles. + // Mantenga el puntero para ver las descripciones de los existentes atributos. + // Para más información, visite: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "dartness_flutter_melos", + "request": "launch", + "type": "dart" + }, + { + "name": "my_app", + "cwd": "apps\\my_app", + "request": "launch", + "program": "lib/main.dart", + "flutterMode": "debug", + "type": "dart" + }, + { + "name": "my_app (profile mode)", + "cwd": "apps\\my_app", + "request": "launch", + "type": "dart", + "flutterMode": "profile" + }, + { + "name": "my_app (release mode)", + "cwd": "apps\\my_app", + "request": "launch", + "type": "dart", + "flutterMode": "release" + }, + { + "name": "my_server", + "cwd": "servers\\my_server", + "request": "launch", + "program": "bin\\my_server.dart", + "type": "dart" + } + ] +} diff --git a/examples/dartness_simple/lib/src/app.dart b/examples/dartness_simple/lib/src/app.dart index e9d8f5df..8169bf7c 100644 --- a/examples/dartness_simple/lib/src/app.dart +++ b/examples/dartness_simple/lib/src/app.dart @@ -2,6 +2,7 @@ import 'package:dartness_server/dartness.dart'; import 'package:dartness_server/modules.dart'; import 'package:dartness_server/server.dart'; import 'package:dio/dio.dart'; +import 'package:example/src/schedulers/example_scheduler.dart'; import 'controllers/city_controller.dart'; import 'controllers/todos_controller.dart'; @@ -28,6 +29,9 @@ Dio createDio() => Dio(); classType: Dio, useFactory: createDio, ), + ProviderMetadata( + classType: ExampleScheduler, + ) ], imports: [ userModule, diff --git a/examples/dartness_simple/lib/src/app.g.dart b/examples/dartness_simple/lib/src/app.g.dart index 0fc08d57..6bff9052 100644 --- a/examples/dartness_simple/lib/src/app.g.dart +++ b/examples/dartness_simple/lib/src/app.g.dart @@ -24,6 +24,7 @@ extension AppExtension on App { injectRegister.register( TodosController(injectRegister.resolve())); injectRegister.register(ExampleErrorHandler()); + injectRegister.register(ExampleScheduler()); } Future init() async { @@ -41,5 +42,6 @@ extension AppExtension on App { port: 8080, ), ); + injectRegister.resolve().initSchedules(); } } diff --git a/examples/dartness_simple/lib/src/schedulers/example_scheduler.dart b/examples/dartness_simple/lib/src/schedulers/example_scheduler.dart new file mode 100644 index 00000000..17afb9c5 --- /dev/null +++ b/examples/dartness_simple/lib/src/schedulers/example_scheduler.dart @@ -0,0 +1,11 @@ +import 'package:dartness_server/schedule.dart'; + +part 'example_scheduler.g.dart'; + +@Scheduler() +class ExampleScheduler { + @Scheduled(cron: "* * * * *") + void example() { + print("${DateTime.now()} Hello world"); + } +} diff --git a/examples/dartness_simple/lib/src/schedulers/example_scheduler.g.dart b/examples/dartness_simple/lib/src/schedulers/example_scheduler.g.dart new file mode 100644 index 00000000..a9a4b589 --- /dev/null +++ b/examples/dartness_simple/lib/src/schedulers/example_scheduler.g.dart @@ -0,0 +1,14 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'example_scheduler.dart'; + +// ************************************************************************** +// SchedulerGenerator +// ************************************************************************** + +extension ExampleSchedulerExtension on ExampleScheduler { + void initSchedules() { + final scheduler0 = SchedulerManager("* * * * *"); + scheduler0.start(example); + } +} diff --git a/examples/dartness_simple/pubspec.yaml b/examples/dartness_simple/pubspec.yaml index 76e8363e..de6bfde8 100644 --- a/examples/dartness_simple/pubspec.yaml +++ b/examples/dartness_simple/pubspec.yaml @@ -8,11 +8,13 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - dartness_server: ^0.6.0 + dartness_server: + path: ../../packages/dartness_server dio: ^5.3.3 dev_dependencies: build_runner: ^2.4.6 - dartness_generator: ^0.6.0 - lints: ^3.0.0 + dartness_generator: + path: ../../packages/dartness_generator + lints: ^4.0.0 test: ^1.24.9