Skip to content

Commit ebfd815

Browse files
authored
Merge pull request #309 from DevKor-github/306-schedule-preparing-logic-refactor
306 schedule preparing logic refactor
2 parents b3b587d + 6f5233c commit ebfd815

File tree

24 files changed

+1386
-234
lines changed

24 files changed

+1386
-234
lines changed

docs/Architecture.md

Lines changed: 402 additions & 0 deletions
Large diffs are not rendered by default.

docs/Git.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
## Git Strategy
2+
3+
## Commit Message Formats
4+
5+
### Default
6+
<pre>
7+
<b><a href="#types">&lt;type&gt;</a></b></font>(<b><a href="#scopes">&lt;optional scope&gt;</a></b>): <b><a href="#description">&lt;description&gt;</a></b>
8+
<sub>empty separator line</sub>
9+
<b><a href="#body">&lt;optional body&gt;</a></b>
10+
<sub>empty separator line</sub>
11+
<b><a href="#footer">&lt;optional footer&gt;</a></b>
12+
</pre>
13+
14+
### Types
15+
* API relevant changes
16+
* `feat` Commits, that add or remove a new feature
17+
* `fix` Commits, that fixes a bug
18+
* `refactor` Commits, that rewrite/restructure your code, however, does not change any API behavior
19+
* `perf` Commits are special `refactor` commits, that improve performance
20+
* `style` Commits, that do not affect the meaning (white-space, formatting, missing semi-colons, etc)
21+
* `test` Commits, that add missing tests or correct existing tests
22+
* `docs` Commits, that affect documentation only
23+
* `build` Commits affect build components like build tool, ci pipeline, dependencies, project version, ...
24+
* `ops` Commits affect operational components like infrastructure, deployment, backup, recovery, ...
25+
* `chore` Miscellaneous commits e.g. modifying `.gitignore`
26+
27+
### Scopes
28+
The `scope` provides additional contextual information.
29+
* Is an **optional** part of the format
30+
* Allowed Scopes depends on the specific project
31+
* Don't use issue identifiers as scopes
32+
33+
### Breaking Changes Indicator
34+
Breaking changes should be indicated by an `!` before the `:` in the subject line e.g. `feat(api)!: remove status endpoint`
35+
* Is an **optional** part of the format
36+
37+
### Description
38+
The `description` contains a concise description of the change.
39+
* Is a **mandatory** part of the format
40+
* Use the imperative, present tense: "change" not "changed" nor "changes"
41+
* Think of `This commit will...` or `This commit should...`
42+
* Don't capitalize the first letter
43+
* No dot (`.`) at the end
44+
45+
### Body
46+
The `body` should include the motivation for the change and contrast this with previous behavior.
47+
* Is an **optional** part of the format
48+
* Use the imperative, present tense: "change" not "changed" nor "changes"
49+
* This is the place to mention issue identifiers and their relations
50+
51+
### Footer
52+
The `footer` should contain any information about **Breaking Changes** and is also the place to **reference Issues** that this commit refers to.
53+
* Is an **optional** part of the format
54+
* **optionally** reference an issue by its id.
55+
* **Breaking Changes** should start with the word `BREAKING CHANGES:` followed by space or two newlines. The rest of the commit message is then used for this.
56+
57+
58+
### Examples
59+
* ```
60+
feat: add email notifications on new direct messages
61+
```
62+
* ```
63+
feat(shopping cart): add the amazing button
64+
```
65+
* ```
66+
feat!: remove ticket list endpoint
67+
68+
refers to JIRA-1337
69+
70+
BREAKING CHANGES: ticket endpoints no longer support listing all entities.
71+
```
72+
* ```
73+
fix(shopping-cart): prevent ordering an empty shopping cart
74+
```
75+
* ```
76+
fix(api): fix the wrong calculation of the request body checksum
77+
```
78+
* ```
79+
fix: add a missing parameter to a service call
80+
81+
The error occurred because of <reasons>.
82+
```
83+
* ```
84+
perf: decrease memory footprint to determine uniqe visitors by using HyperLogLog
85+
```
86+
* ```
87+
build: update dependencies
88+
```
89+
* ```
90+
build(release): bump version to 1.0.0
91+
```
92+
* ```
93+
refactor: Implement Fibonacci number calculation as recursion
94+
```
95+
* ```
96+
style: remove empty line
97+
```
98+
99+
---

docs/Home.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# OnTime Flutter Project Wiki
2+
3+
Welcome to the OnTime-front project documentation! This wiki contains everything new developers need to understand and contribute to the project.
4+
5+
## 📚 Documentation Index
6+
7+
### Getting Started
8+
- [Wiki Management Guide](./Wiki-Management.md) - How to modify and upload wiki content
9+
- [Project Architecture](./Architecture.md) - Understanding the project structure
10+
- [Git Workflow](./Git.md) - Git strategy and commit message formats
11+
12+
### Development Resources
13+
- 🚧 **Getting Started Guide** *(Coming Soon)* - Setup and installation
14+
- 🚧 **Development Guide** *(Coming Soon)* - Development workflow and best practices
15+
- 🚧 **API Documentation** *(Coming Soon)* - Backend API reference
16+
- 🚧 **Testing Guide** *(Coming Soon)* - Testing procedures and guidelines
17+
18+
## 🎯 Quick Links
19+
20+
- [Main Repository](https://github.com/DevKor-github/OnTime-front)
21+
- [Issues](https://github.com/DevKor-github/OnTime-front/issues)
22+
- [Pull Requests](https://github.com/DevKor-github/OnTime-front/pulls)
23+
- [Widgetbook](https://on-time-front-widgetbook.web.app/)
24+
25+
## 🤝 Contributing
26+
27+
New to the project? Start here:
28+
29+
1. **Read the [Wiki Management Guide](./Wiki-Management.md)** to understand how documentation works
30+
2. **Review the [Architecture](./Architecture.md)** to understand the project structure
31+
3. **Follow the [Git Workflow](./Git.md)** for consistent development practices
32+
4. **Set up your development environment** *(guide coming soon)*
33+
34+
## 📝 Need Help?
35+
36+
- Create an issue for bugs or feature requests
37+
- Ask questions in team discussions
38+
- Contribute to documentation improvements
39+
40+
---
41+
42+
*This wiki is maintained by the OnTime development team and integrated with the main repository.*

docs/Schedule-Timer-System.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Schedule Timer System
2+
3+
The OnTime app includes an automatic timer system within the `ScheduleBloc` that manages precise timing for schedule start notifications. This system ensures that schedule start events are triggered at the exact scheduled time.
4+
5+
## 🎯 Overview
6+
7+
The timer system automatically:
8+
9+
- Starts when an upcoming schedule is received
10+
- Triggers a `ScheduleStarted` event at exactly x minute 00 seconds
11+
- Handles proper cleanup and timer management
12+
- Ensures thread-safety and prevents memory leaks
13+
14+
## 🔄 Timer Flow
15+
16+
```mermaid
17+
sequenceDiagram
18+
participant UC as UseCase
19+
participant SB as ScheduleBloc
20+
participant Timer as Timer
21+
participant State as State
22+
23+
UC->>SB: ScheduleUpcomingReceived(schedule)
24+
SB->>SB: Cancel existing timer
25+
SB->>SB: _startScheduleTimer(schedule)
26+
SB->>Timer: Create Timer(targetTime)
27+
Note over Timer: Timer set for schedule.scheduleTime<br/>at x minute 00 seconds
28+
SB->>State: emit(ScheduleState.upcoming/ongoing)
29+
30+
Timer-->>SB: Timer fires at exact minute
31+
SB->>SB: add(ScheduleStarted())
32+
SB->>SB: _onScheduleStarted()
33+
SB->>State: emit(ScheduleState.started)
34+
35+
Note over SB: Timer cleanup on close()<br/>or new schedule received
36+
```
37+
38+
## 📋 Implementation Details
39+
40+
### Key Components
41+
42+
1. **Timer Management**
43+
44+
- `_scheduleStartTimer`: Dart Timer instance that handles the countdown
45+
- `_currentScheduleId`: Tracks the active schedule to prevent stale events
46+
47+
2. **Event Handling**
48+
49+
- `ScheduleUpcomingReceived`: Triggers timer setup
50+
- `ScheduleStarted`: Fired when timer completes
51+
52+
3. **State Transitions**
53+
- `upcoming``started`: When timer fires for upcoming schedules
54+
- `ongoing``started`: When timer fires for preparation-in-progress schedules
55+
56+
### Timer Calculation
57+
58+
The timer calculates the exact target time as:
59+
60+
```dart
61+
final targetTime = DateTime(
62+
scheduleTime.year,
63+
scheduleTime.month,
64+
scheduleTime.day,
65+
scheduleTime.hour,
66+
scheduleTime.minute,
67+
0, // Always trigger at 00 seconds
68+
0, // 0 milliseconds
69+
);
70+
```
71+
72+
### Safety Features
73+
74+
- **Timer Cancellation**: Previous timers are automatically cancelled when new schedules arrive
75+
- **Bloc State Validation**: Timer callbacks verify the bloc is still active before firing events
76+
- **Schedule ID Matching**: Events only fire for the currently tracked schedule
77+
- **Proper Cleanup**: All timers are cancelled when the bloc is disposed
78+
79+
## 🛡️ Error Handling
80+
81+
The system includes several safety mechanisms:
82+
83+
1. **Past Schedule Protection**: Timers are not set for schedules in the past
84+
2. **Bloc Lifecycle Management**: Timer callbacks check `isClosed` before adding events
85+
3. **Memory Leak Prevention**: All timers are properly cancelled in `close()`
86+
4. **Race Condition Prevention**: Schedule ID tracking prevents stale timer events
87+
88+
## 📱 Usage Example
89+
90+
The timer system works automatically within the `ScheduleBloc`:
91+
92+
```dart
93+
// When a new schedule is received
94+
bloc.add(ScheduleSubscriptionRequested());
95+
96+
// The bloc will:
97+
// 1. Listen for upcoming schedules
98+
// 2. Automatically start timers for each schedule
99+
// 3. Emit ScheduleStarted events at the exact scheduled time
100+
// 4. Transition to 'started' state
101+
102+
// Listen for state changes
103+
bloc.stream.listen((state) {
104+
if (state.status == ScheduleStatus.started) {
105+
// Handle schedule start (e.g., show notification, start tracking)
106+
}
107+
});
108+
```
109+
110+
## 🔧 Configuration
111+
112+
The timer system requires no additional configuration and works automatically with:
113+
114+
- Any `ScheduleWithPreparationEntity` that has a valid `scheduleTime`
115+
- Both upcoming and ongoing schedule states
116+
- All timezone-aware DateTime calculations
117+
118+
## 📊 Performance Considerations
119+
120+
- **Single Timer**: Only one timer runs at a time per bloc instance
121+
- **Minimal Memory Footprint**: Timers are created/destroyed as needed
122+
- **Precise Timing**: Uses Dart's native Timer for accurate scheduling
123+
- **Efficient Cleanup**: No lingering resources after bloc disposal
124+
125+
## 🚀 Future Enhancements
126+
127+
Potential improvements to consider:
128+
129+
- Multiple concurrent schedule timers
130+
- Configurable timer precision (seconds vs milliseconds)
131+
- Timer persistence across app restarts
132+
- Integration with system-level scheduling APIs

0 commit comments

Comments
 (0)