Increment error count with daily reset Updates two counters: - error_count: Historical total errors (never reset) - consecutive_error_count: Consecutive errors (reset on success/enable) - today_error_count: Today's errors (reset on date change)
(self, token_id: int)
| 1279 | await db.commit() |
| 1280 | |
| 1281 | async def increment_error_count(self, token_id: int): |
| 1282 | """Increment error count with daily reset |
| 1283 | |
| 1284 | Updates two counters: |
| 1285 | - error_count: Historical total errors (never reset) |
| 1286 | - consecutive_error_count: Consecutive errors (reset on success/enable) |
| 1287 | - today_error_count: Today's errors (reset on date change) |
| 1288 | """ |
| 1289 | async with self._connect(write=True) as db: |
| 1290 | today = self._current_stats_date() |
| 1291 | # Get current stats |
| 1292 | cursor = await db.execute("SELECT today_date FROM token_stats WHERE token_id = ?", (token_id,)) |
| 1293 | row = await cursor.fetchone() |
| 1294 | |
| 1295 | # If date changed, reset all daily counters before recording today's error. |
| 1296 | if row and row[0] != today: |
| 1297 | await db.execute(""" |
| 1298 | UPDATE token_stats |
| 1299 | SET error_count = error_count + 1, |
| 1300 | consecutive_error_count = consecutive_error_count + 1, |
| 1301 | today_image_count = 0, |
| 1302 | today_video_count = 0, |
| 1303 | today_error_count = 1, |
| 1304 | today_date = ?, |
| 1305 | last_error_at = CURRENT_TIMESTAMP |
| 1306 | WHERE token_id = ? |
| 1307 | """, (today, token_id)) |
| 1308 | else: |
| 1309 | # Same day, just increment all counters |
| 1310 | await db.execute(""" |
| 1311 | UPDATE token_stats |
| 1312 | SET error_count = error_count + 1, |
| 1313 | consecutive_error_count = consecutive_error_count + 1, |
| 1314 | today_error_count = today_error_count + 1, |
| 1315 | today_date = ?, |
| 1316 | last_error_at = CURRENT_TIMESTAMP |
| 1317 | WHERE token_id = ? |
| 1318 | """, (today, token_id)) |
| 1319 | await db.commit() |
| 1320 | |
| 1321 | async def reset_error_count(self, token_id: int): |
| 1322 | """Reset consecutive error count (only reset consecutive_error_count, keep error_count and today_error_count) |
no test coverage detected