Commit 6a44f17
authored
fix: Ensure persist state event emission when exiting
### Description
- Fixes root cause for flakiness in
`test_crawler_statistics_persistence`
- Previously, `BasicCrawler` was manually emitting a persist state event
when exiting. Now this should be done by the `EventManager`.
- Statistics used to be double-persisted previously, and due to a race
condition, the old state could be persisted sometimes. Now the
statistics are persisted by themselves when exiting their own context,
and not by the Crawler-emitted event
- `StatisticsState.crawler_runtime` changed to a computed field in a
backwards compatible way. This allows pushing the runtime calculation to
the state and ensures consistency between attribute access and
persistence. (This prevents a theoretical race condition when automatic
persistence triggers almost at the same time as the crawler finishes,
and again causes the scenario described above).
### Issues
- Closes: #1560
### Testing
- Stress testing in CI
- Added unit test
### Checklist
- [x] CI passedEventManager context (#1562)1 parent 4b41e97 commit 6a44f17
File tree
6 files changed
+50
-28
lines changed- src/crawlee
- crawlers/_basic
- events
- statistics
- tests/unit
- crawlers/_basic
- events
6 files changed
+50
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| |||
751 | 751 | | |
752 | 752 | | |
753 | 753 | | |
754 | | - | |
755 | | - | |
756 | | - | |
757 | 754 | | |
758 | 755 | | |
759 | 756 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
133 | 136 | | |
134 | 137 | | |
135 | 138 | | |
136 | 139 | | |
137 | | - | |
138 | 140 | | |
139 | 141 | | |
140 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
79 | | - | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
96 | 127 | | |
97 | 128 | | |
98 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | 113 | | |
117 | 114 | | |
118 | 115 | | |
| |||
168 | 165 | | |
169 | 166 | | |
170 | 167 | | |
171 | | - | |
172 | | - | |
| 168 | + | |
| 169 | + | |
173 | 170 | | |
174 | 171 | | |
175 | 172 | | |
| |||
200 | 197 | | |
201 | 198 | | |
202 | 199 | | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | 200 | | |
208 | 201 | | |
209 | 202 | | |
| |||
262 | 255 | | |
263 | 256 | | |
264 | 257 | | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | 258 | | |
274 | 259 | | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | 260 | | |
280 | 261 | | |
281 | 262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1673 | 1673 | | |
1674 | 1674 | | |
1675 | 1675 | | |
1676 | | - | |
1677 | 1676 | | |
1678 | 1677 | | |
1679 | 1678 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
207 | 208 | | |
208 | 209 | | |
209 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
0 commit comments