-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (38 loc) · 1.38 KB
/
main.py
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
import logging
import sys
from datetime import datetime
from classes import Archive, Destination
from config import archive, destination
logging.basicConfig()
logging.getLogger().setLevel(logging.INFO)
def restore_objects(
onThatDay: datetime, archive: Archive, destination: Destination
) -> None:
if onThatDay > datetime.now():
logging.error(f"Restoring from {onThatDay} is not allowed")
sys
exit(1)
if not archive.check_connectivity:
logging.error(f"Archive host {archive.host} unreachable!")
sys.exit(1)
if not archive.check_compliancy_bucket:
logging.error(f"Bucket {archive.compliancy_bucket} not found")
sys.exit(1)
if not destination.check_connectivity:
logging.error(f"Destination host {destination.host} unreachable!")
sys.exit(1)
# Process ndjson.gz Objects in bucket
objects = archive.list_objects(onThatDay)
for obj in objects:
logging.info(obj.object_name)
# Decode .gz
lines = archive.get_lines(obj.object_name)
# send ndjson ( multi lines )
status = destination.sendMultiLines(lines)
logging.info(f"Event sent, status {status}")
return None
if __name__ == "__main__":
# Select a given day
onThatDay = datetime(2023, 12, 1)
# Restore that day from archive to destination
restore_objects(onThatDay, archive, destination)