Commit f21957d
committed
Merge #1531: Overhaul stats: Simplify how the
67d177b refactor: [#1524] command/query separation (Jose Celano)
8c31549 refactor: [#1524] rename methods (Jose Celano)
28603fe refactor: [#1524] extract TestEnv for integration tests in tracker-core (Jose Celano)
ab2f52d fix: [#1524] test (move to integration test) (Jose Celano)
b05bccd refactor: [#1524] integration tests in tracker-core (Jose Celano)
f3d3495 refactor: [#1524] remove duplciate code for tracker core container (Jose Celano)
e90585a refactor: [#1524] move total downloads udpate from announce command to event handler (Jose Celano)
8968757 refactor: extract method JobManger::push_opt (Jose Celano)
7e933f9 feat: [#1524] listens to torrent-repository events in the tracker-core pkg (Jose Celano)
3a23a38 fix: tracing message (Jose Celano)
Pull request description:
Simplify how the `AnnounceHandler` persist number of downloads in `tracker-core` package.
It's now done asynchronously instead of synchronously.
**NOTICE:** That `bittorrent_tracker_core::announce_handler::AnnounceHandler::announce` will not return a database error anymore, meaning the peer will receive the announce response even if the tracker can't update the downloads counter.
### Subtasks
Main change:
- [x] Scaffolding for listening to torrent-repository events in the `tracker-core` package.
- [x] Move the SQL update from the `AnnounceHandler` to the event handler (`handle_event`).
Cleanup:
- [x] Fix test. https://github.com/torrust/torrust-tracker/actions/runs/15168471742/job/42652507081?pr=1531#step:7:250
- It's not the service's responsibility to increment the counter anymore. Add:
- A unit test in the event handler to check that the counter is increased when the event is received.
- An integration test to simulate a peer completing downloading.
- Maybe we should also add a main app E2E test (to make sure the listener is initialised), but we are not testing it for other jobs directly. We have to review the strategy for E2E tests in the main app.
- [x] Refactor: rename `upsert_peer` to `handle_announcement`.
- [x] Refactor: rename `AnnounceHandler::announce` to `AnnounceHandler::handle_announcement`
- [x] Refactor: Don't return the boolean `number of downloads increased` in `upsert_peer`. `upsert_peer` should only be a command decoupled from other secondary tasks. Side effects should be captured from events.
NOTE: I cannot remove the `db_torrent_repository` dependency from the `AnnounceHandler` yet until we implement the new persistent metric for the number of downloads, because it's still used in:
```rust
let opt_persistent_torrent = if self.config.tracker_policy.persistent_torrent_completed_stat {
self.db_torrent_repository.load(info_hash)?
} else {
None
};
```
ACKs for top commit:
josecelano:
ACK 67d177b
Tree-SHA512: 5d33fc5e383d280dda68879c165f736729c0659a1f69136ef2fbc48ed35e7a87e4cbf4ba30e5654f2192a3dbeabe4d474f8f5c54ae310320a2888b234ecf9614AnnounceHandler persist number of downloads in tracker-core packageFile tree
32 files changed
+560
-405
lines changed- packages
- axum-http-tracker-server/src
- axum-rest-tracker-api-server/src
- http-tracker-core/src/services
- torrent-repository/src
- tracker-core
- src
- statistics
- event
- torrent
- repository
- tests
- common
- udp-tracker-core/src/services
- udp-tracker-server/src
- handlers
- src
- bootstrap/jobs
32 files changed
+560
-405
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
| 32 | + | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
| 40 | + | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| |||
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
294 | | - | |
| 294 | + | |
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
| |||
482 | 482 | | |
483 | 483 | | |
484 | 484 | | |
485 | | - | |
| 485 | + | |
486 | 486 | | |
487 | 487 | | |
488 | 488 | | |
| |||
0 commit comments