|
6 | 6 | import platform
|
7 | 7 | from pathlib import Path
|
8 | 8 |
|
| 9 | +import schedule |
| 10 | + |
9 | 11 |
|
10 |
| -START_SLEEP = 3600 |
11 | 12 | S3_BUCKET = 's3://aisonobuoy-pibuoy-v2/compressed/'
|
12 | 13 | FLASH_DIR = '/flash'
|
13 | 14 | TELEMETRY_DIR = os.path.join(FLASH_DIR, 'telemetry')
|
@@ -56,24 +57,30 @@ def tar_dir(filedir, tarfile, xz=False):
|
56 | 57 | return False
|
57 | 58 |
|
58 | 59 |
|
| 60 | +def job(hostname): |
| 61 | + timestamp = int(time.time()) |
| 62 | + if not os.path.exists(S3_DIR): |
| 63 | + os.mkdir(S3_DIR) |
| 64 | + |
| 65 | + for telemetry, xz in TELEMETRY_TYPES: |
| 66 | + filedir = os.path.join(TELEMETRY_DIR, telemetry) |
| 67 | + if not os.path.exists(filedir): |
| 68 | + os.mkdir(filedir) |
| 69 | + tarfile = f'{S3_DIR}/{telemetry}-{hostname}-{timestamp}.tar' |
| 70 | + if xz: |
| 71 | + tarfile = tarfile + '.xz' |
| 72 | + print(f'processing {filedir}, tar {tarfile}') |
| 73 | + tar_dir(filedir, tarfile, xz=xz) |
| 74 | + s3_copy(S3_DIR) |
| 75 | + return |
| 76 | + |
| 77 | + |
59 | 78 | def main():
|
60 | 79 | hostname = os.getenv("HOSTNAME", platform.node())
|
| 80 | + schedule.every().day.at("13:00").do(job, hostname) |
61 | 81 | while True:
|
62 |
| - time.sleep(START_SLEEP) |
63 |
| - timestamp = int(time.time()) |
64 |
| - if not os.path.exists(S3_DIR): |
65 |
| - os.mkdir(S3_DIR) |
66 |
| - |
67 |
| - for telemetry, xz in TELEMETRY_TYPES: |
68 |
| - filedir = os.path.join(TELEMETRY_DIR, telemetry) |
69 |
| - if not os.path.exists(filedir): |
70 |
| - os.mkdir(filedir) |
71 |
| - tarfile = f'{S3_DIR}/{telemetry}-{hostname}-{timestamp}.tar' |
72 |
| - if xz: |
73 |
| - tarfile = tarfile + '.xz' |
74 |
| - print(f'processing {filedir}, tar {tarfile}') |
75 |
| - tar_dir(filedir, tarfile, xz=xz) |
76 |
| - s3_copy(S3_DIR) |
| 82 | + schedule.run_pending() |
| 83 | + time.sleep(60) |
77 | 84 |
|
78 | 85 |
|
79 | 86 | if __name__ == '__main__':
|
|
0 commit comments