Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Scheduler pattern #76 #3135

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Nothere998
Copy link

In many applications, it is necessary to manage and execute tasks (or jobs) at specific intervals or under certain conditions. Examples include running periodic background tasks, sending scheduled notifications, or automating repetitive processes. However, managing these tasks manually can lead to several challenges:

Lack of Modularity: Without a well-structured design, the logic for task execution may become entangled with application logic, reducing code readability and maintainability.
Hardcoding of Triggers: Defining triggers inline or directly in the task logic makes it hard to reuse or update the triggers without modifying the entire task.
No Centralized Management: The absence of a centralized scheduler results in scattered execution logic, making debugging and scalability difficult.
Inflexibility: Hardcoded schedules or conditions prevent the easy addition or modification of tasks and triggers.

The goal was to design a scheduling pattern that decouples jobs from their execution triggers, promotes reusability, and centralizes the scheduling logic.

Nothere998 and others added 6 commits December 7, 2024 17:50
issue This PR Solves
In microservices, logs are often collected using busy waiting loops, where the system constantly checks for new logs. This leads to several issues:

Wasting Resources: The system keeps checking for new logs, using up CPU resources even when there are no logs to process.

Increased Latency: Logs are delayed because the system is busy checking for new data rather than processing logs as they arrive.   

This PR solves these problems by switching to a more efficient event-driven log aggregation system. Instead of constantly checking for new logs, the system reacts only when new logs are available, reducing unnecessary CPU usage and improving scalability and performance.
The Scheduler design pattern provides a clean and structured solution to manage and execute tasks automatically. It involves:

Scheduler: A component responsible for managing the execution of tasks, ensuring they run at the correct time or under the right conditions.
Task: A unit of work that encapsulates the logic to be executed.
Trigger/Condition: Defines when and how often a task should execute, whether it's based on time intervals (e.g., every minute) or events 
Execution Context: Ensures that tasks are executed in the right environment, managing resources, states, and concurrency.

By using this pattern, tasks are managed centrally, execution timing is automated, and the system can handle various triggers and execution conditions efficiently, allowing developers to focus on defining what needs to be done instead of when and how to execute it.
Copy link

sonarqubecloud bot commented Dec 7, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
D Maintainability Rating on New Code (required ≥ A)
D Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

jobs.add(job);
triggers.add(trigger);
}
public void start() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually we use spring boot and the framework itself provides centralized system and the dev just needs to use specific stereotype annotations to schedule job with configs

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants