How nikunja11/task-scheduler works
Project type and purpose
• This is a Java-based task scheduling library (packaged via Maven). There is no UI or network layer; instead it provides a core scheduling engine you embed in your application to define, store, and execute units of work (Tasks) via an event-driven, state-machine approach.
File structure
• pom.xml: Maven build, dependency management.
• src/main/java/com/scheduler/core: interfaces and abstractions (Task, InputProvider, TaskExecutor, TaskExecutionContext).
• com/scheduler/event: event definitions, a publisher and a bus to broadcast WorkflowEvents.
• com/scheduler/listener: event listener interfaces and example implementation (LoggingEventListener).
• com/scheduler/repo: repository interfaces and an in-memory implementation for storing task metadata.
• com/scheduler/scheduler: the TaskScheduler component that orchestrates task lifecycles.
• com/scheduler/state: a state-pattern implementation for TaskState (Init, Ready, Running, Success, Failed).
• com/scheduler/examples: sample code exercising the library (DataProcessingExample).
README
• Minimal: the project name. We infer from code structure that the focus is on an embeddable, event-driven scheduler.
a. Main components
• TaskScheduler – the orchestrator that polls the repository, transitions states, and triggers execution.
• TaskRepository – persistent store for task definitions and statuses (e.g. InMemoryTaskRepository).
• TaskState Machine – encapsulates valid state transitions (Init → Ready → Running → Success/Failed).
• TaskExecutor – invokes the actual work defined by a Task implementation via TaskExecutionContext and InputProvider.
• WorkflowEventBus & TaskEventPublisher – event-driven communication channel for broadcasting state changes.
• WorkflowEventListener(s) – e.g. LoggingEventListener, user-provided hooks for reacting to events.
• Example client code – DataProcessingExample, illustrating how an application uses the above components.
b. Relationships and interactions
1. Client code instantiates and configures TaskScheduler, injecting a TaskRepository, TaskExecutor, InputProvider, and optionally listeners.
2. TaskScheduler polls or is triggered to pick up pending tasks from TaskRepository.
3. For each fetched Task, TaskScheduler drives the state machine: calls state.enter/exit methods, updates the TaskState in the repository.
4. Before and after each state transition, TaskEventPublisher posts WorkflowEvents onto WorkflowEventBus.
5. Registered WorkflowEventListeners receive events and perform side-effects (e.g., logging, metrics, retries).
6. When a task reaches the Running state, TaskScheduler invokes TaskExecutor.execute(context) which runs the actual Task logic.
7. Upon completion or exception, TaskExecutor signals success or failure, triggering a state transition to SuccessTaskState or FailedState.
8. Final state is persisted, relevant events are published, and scheduling continues or terminates.
c. Architectural patterns and principles
• State Pattern: TaskState classes encapsulate behavior per state.
• Event-Driven: decoupled communication via WorkflowEventBus and listeners.
• Dependency Injection (via constructors) to swap repository or executor implementations.
• Modular layering: core abstractions vs. pluggable implementations vs. application examples.
d. Key technologies and frameworks
• Java 8+
• Maven (pom.xml)
• No external frameworks by default; all components are custom (could be extended to use Spring DI, a database-backed TaskRepository, etc.).