Skip to content

Commit cddb915

Browse files
authored
Merge pull request #588 from cglewis/main
switch to only uploading once a day
2 parents 6556f6d + 76951ef commit cddb915

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
awscli==1.22.58
2+
schedule==1.1.0

PiBuoyV2/services/s3-upload/s3_app.py

+23-16
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import platform
77
from pathlib import Path
88

9+
import schedule
10+
911

10-
START_SLEEP = 3600
1112
S3_BUCKET = 's3://aisonobuoy-pibuoy-v2/compressed/'
1213
FLASH_DIR = '/flash'
1314
TELEMETRY_DIR = os.path.join(FLASH_DIR, 'telemetry')
@@ -56,24 +57,30 @@ def tar_dir(filedir, tarfile, xz=False):
5657
return False
5758

5859

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+
5978
def main():
6079
hostname = os.getenv("HOSTNAME", platform.node())
80+
schedule.every().day.at("13:00").do(job, hostname)
6181
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)
7784

7885

7986
if __name__ == '__main__':

0 commit comments

Comments
 (0)