-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettlement_checker.py
More file actions
59 lines (44 loc) · 1.52 KB
/
settlement_checker.py
File metadata and controls
59 lines (44 loc) · 1.52 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
"""
Settlement checker service that runs in the background.
Checks split table every 10 minutes and updates is_settled status for expenses.
"""
from database import SplitDataDB
import signal
import sys
def signal_handler(sig, frame):
"""Handle Ctrl+C gracefully."""
print('\n\nShutting down settlement checker...')
sys.exit(0)
def main():
"""Run the settlement checker service."""
# Register signal handler for graceful shutdown
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
db = SplitDataDB()
try:
# Connect to database
if not db.connect():
print("Failed to connect to database. Exiting.")
return
print("="*60)
print("SETTLEMENT CHECKER SERVICE")
print("="*60)
print("This service checks the split table every 10 minutes")
print("and updates is_settled status for expenses.")
print("="*60)
# Run initial check
print("\nRunning initial check...")
db.update_settled_expenses()
# Start the scheduler
scheduler_thread = db.start_settlement_checker(interval_minutes=10)
# Keep the main thread alive
try:
scheduler_thread.join()
except KeyboardInterrupt:
print('\n\nShutting down settlement checker...')
except Exception as e:
print(f"Error: {e}")
finally:
db.disconnect()
if __name__ == "__main__":
main()