Added logs cleanup
All checks were successful
Deploy dev on push / on-push-deploy_sh-edraft (push) Successful in 4m30s
All checks were successful
Deploy dev on push / on-push-deploy_sh-edraft (push) Successful in 4m30s
This commit is contained in:
parent
0d3db75190
commit
bc94d31a8d
22
bot/src/bot/extension/clean_logs_extension.py
Normal file
22
bot/src/bot/extension/clean_logs_extension.py
Normal file
@ -0,0 +1,22 @@
|
||||
import os
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.application.application_extension_abc import ApplicationExtensionABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
|
||||
class CleanLogsExtension(ApplicationExtensionABC):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
async def run(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
(
|
||||
List(str, os.listdir("logs/"))
|
||||
.where(lambda x: os.path.isdir(f"logs/{x}"))
|
||||
.order_by()
|
||||
.where(lambda x: (datetime.now() - datetime.strptime(x, "%Y-%m-%d")).days >= 7)
|
||||
.for_each(lambda x: shutil.rmtree(f"logs/{x}"))
|
||||
)
|
@ -6,6 +6,7 @@ from cpl_core.application import ApplicationBuilder
|
||||
from cpl_core.console import Console
|
||||
|
||||
from bot.application import Application
|
||||
from bot.extension.clean_logs_extension import CleanLogsExtension
|
||||
from bot.extension.init_bot_extension import InitBotExtension
|
||||
from bot.startup import Startup
|
||||
from bot.startup_discord_extension import StartupDiscordExtension
|
||||
@ -31,6 +32,7 @@ class Program:
|
||||
.use_extension(StartupDiscordExtension)
|
||||
.use_extension(StartupModuleExtension)
|
||||
.use_extension(StartupMigrationExtension)
|
||||
.use_extension(CleanLogsExtension)
|
||||
.use_extension(DatabaseExtension)
|
||||
.use_extension(ConfigExtension)
|
||||
.use_extension(InitBotExtension)
|
||||
|
Loading…
Reference in New Issue
Block a user