-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
81 lines (62 loc) · 2.14 KB
/
Copy pathrun.py
File metadata and controls
81 lines (62 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from apscheduler.schedulers.background import BackgroundScheduler
from app import create_app
from app.config import Config
from app.core.file_manager import ensure_folder_exists
from app.jobs.cleanup_files import cleanup_all_feature_files
def create_storage_folders() -> None:
storage_folders = [
Config.COMPARE_RECEIVED_FOLDER,
Config.COMPARE_PROCESSED_FOLDER,
Config.COMPARE_TEMP_FOLDER,
Config.EXTRACT_TEXT_RECEIVED_FOLDER,
Config.EXTRACT_TEXT_PROCESSED_FOLDER,
Config.EXTRACT_TEXT_TEMP_FOLDER,
Config.SPLIT_PDF_RECEIVED_FOLDER,
Config.SPLIT_PDF_PROCESSED_FOLDER,
Config.SPLIT_PDF_TEMP_FOLDER,
Config.MERGE_PDF_RECEIVED_FOLDER,
Config.MERGE_PDF_PROCESSED_FOLDER,
Config.MERGE_PDF_TEMP_FOLDER,
Config.OCR_PDF_RECEIVED_FOLDER,
Config.OCR_PDF_PROCESSED_FOLDER,
Config.OCR_PDF_TEMP_FOLDER,
]
try:
for folder_path in storage_folders:
ensure_folder_exists(folder_path)
print("sucesso. pastas de storage criadas")
except Exception as error:
print(f"falha. pastas de storage não criadas: {error}")
raise
def start_cleanup_scheduler() -> None:
try:
scheduler = BackgroundScheduler(timezone=Config.TIMEZONE_NAME)
scheduler.add_job(
cleanup_all_feature_files,
"interval",
minutes=Config.CLEANUP_INTERVAL_MINUTES,
id="cleanup_all_feature_files",
replace_existing=True,
)
scheduler.start()
print("sucesso. scheduler iniciado")
except Exception as error:
print(f"falha. scheduler não iniciado: {error}")
raise
def start_api() -> None:
try:
flask_app = create_app()
create_storage_folders()
start_cleanup_scheduler()
print("sucesso. api iniciada")
flask_app.run(
host=Config.HOST,
port=Config.PORT,
debug=Config.DEBUG,
use_reloader=False,
)
except Exception as error:
print(f"falha. api não iniciada: {error}")
raise
if __name__ == "__main__":
start_api()