Feature/task scheduling decorators#111
Open
maxsonferovante wants to merge 11 commits intoPythonNest:mainfrom
Open
Feature/task scheduling decorators#111maxsonferovante wants to merge 11 commits intoPythonNest:mainfrom
maxsonferovante wants to merge 11 commits intoPythonNest:mainfrom
Conversation
…ts-tests.txt Add APScheduler, pytz, six, and tzlocal dependencies to the requirements files.
This commit adds a new file `apscheduler.py` to the `nest/core/apscheduler` directory. The file contains the implementation of an instance of the `BackgroundScheduler` class from the APScheduler library. Additionally, a new file `scheduler.py` is added to the `nest/core/decorators` directory. This file contains decorators `Cron` and `Interval` for scheduling functions to run at specific times or intervals.
This commit introduces lifecycle management for the scheduler in the `PyNestApp` class, ensuring the scheduler starts and stops with the application. It also adds functionality to activate scheduled methods for instantiated services, enhancing the scheduling capabilities of the application. New methods `_setup_scheduler_lifecycle` and `_activate_scheduled_methods` are implemented to facilitate these features. Additionally, the `apscheduler` module is updated to include start and stop functions for the scheduler, and the decorators for scheduling tasks are enhanced to ensure proper initialization.
This commit introduces a new test file `test_scheduler.py` that contains unit tests for the `@Cron` and `@Interval` decorators. The tests cover various scenarios, including valid and invalid cron expressions, as well as different parameter configurations for the interval decorator. The tests ensure that the decorators correctly register jobs with the scheduler and handle errors appropriately.
…, service, and scheduler service This commit introduces the `SchedulerApp` module, which includes the main application controller (`AppController`), application service (`AppService`), and scheduler service (`SchedulerService`). The app controller provides endpoints for application information, scheduler statistics, logs, and health checks. The application service offers detailed information about the scheduling system, while the scheduler service implements task scheduling using decorators. A new entry point is also created in `main.py` to run the application with Uvicorn.
This commit updates the `pyproject.toml` file to transition from setuptools to Poetry as the build system. It includes the addition of versioning, authorship, and enhanced dependency management, specifying core and optional dependencies. The project metadata has been updated to reflect the new structure, including homepage and documentation links. The previous optional dependencies have been restructured under Poetry's extras and groups.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task Scheduling Feature for PyNest
This pull request introduces a comprehensive task scheduling system to PyNest, enabling developers to easily schedule background tasks, periodic operations, and automated processes using familiar decorator patterns.
Decorators
@Cron- Schedule tasks with cron expressions:@Interval- Schedule tasks at regular intervals:Seamless PyNest Integration
Works perfectly with PyNest's dependency injection system:
Key Features
Zero Configuration Required
82+ Predefined Cron Expressions
Choose from a comprehensive set of ready-to-use expressions:
EVERY_SECOND,EVERY_5_MINUTES,EVERY_HOUREVERY_DAY_AT_MIDNIGHT,EVERY_DAY_AT_NOONEVERY_WEEKDAY,MONDAY_TO_FRIDAY_AT_9AMEVERY_1ST_DAY_OF_MONTH,EVERY_QUARTERProduction-Ready Features
Dependency Injection Support
@InjectableservicesImplementation Details
Core Components Added
Scheduler Core (
nest/core/apscheduler/)Decorators (
nest/core/decorators/scheduler.py)@Cronand@IntervaldecoratorsEnums (
nest/core/apscheduler/enums/)PyNest Integration (
nest/core/pynest_application.py)Dependencies Added
Documentation & Examples
Complete Documentation
docs/task_scheduling.mdwith comprehensive guideWorking Example Application
examples/SchedulerApp/- Complete PyNest applicationComprehensive Testing
Use Cases
Perfect for:
Getting Started
Install dependencies (automatically handled by requirements files)
Create a scheduled service: