-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat($SQLite): retain logs before the program exits
- Loading branch information
1 parent
dc4274d
commit f310130
Showing
7 changed files
with
96 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import arrow | ||
from loguru import logger | ||
|
||
from python_boilerplate import get_module_name | ||
from python_boilerplate.repository.model.trace_log import TraceLog | ||
|
||
|
||
def save(trace_log: TraceLog) -> TraceLog: | ||
trace_log.save() | ||
return trace_log | ||
|
||
|
||
def retain_trace_log() -> int: | ||
a_week_ago = arrow.now().shift(days=-7).format("YYYY-MM-DD") | ||
affected_rows: int = ( | ||
TraceLog.delete().where(TraceLog.start_time < a_week_ago).execute() | ||
) | ||
# the affected_rows is always 1 no matter how many rows were deleted | ||
logger.debug( | ||
f"The app [{get_module_name()}] retains recent 7 days of trace log. " | ||
f"Deleted {affected_rows} records that are before {a_week_ago}" | ||
) | ||
return affected_rows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters