Skip to content

Commit

Permalink
Merge pull request #588 from cglewis/main
Browse files Browse the repository at this point in the history
switch to only uploading once a day
  • Loading branch information
cglewis authored Feb 20, 2022
2 parents 6556f6d + 76951ef commit cddb915
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions PiBuoyV2/services/s3-upload/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
awscli==1.22.58
schedule==1.1.0
39 changes: 23 additions & 16 deletions PiBuoyV2/services/s3-upload/s3_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import platform
from pathlib import Path

import schedule


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


def job(hostname):
timestamp = int(time.time())
if not os.path.exists(S3_DIR):
os.mkdir(S3_DIR)

for telemetry, xz in TELEMETRY_TYPES:
filedir = os.path.join(TELEMETRY_DIR, telemetry)
if not os.path.exists(filedir):
os.mkdir(filedir)
tarfile = f'{S3_DIR}/{telemetry}-{hostname}-{timestamp}.tar'
if xz:
tarfile = tarfile + '.xz'
print(f'processing {filedir}, tar {tarfile}')
tar_dir(filedir, tarfile, xz=xz)
s3_copy(S3_DIR)
return


def main():
hostname = os.getenv("HOSTNAME", platform.node())
schedule.every().day.at("13:00").do(job, hostname)
while True:
time.sleep(START_SLEEP)
timestamp = int(time.time())
if not os.path.exists(S3_DIR):
os.mkdir(S3_DIR)

for telemetry, xz in TELEMETRY_TYPES:
filedir = os.path.join(TELEMETRY_DIR, telemetry)
if not os.path.exists(filedir):
os.mkdir(filedir)
tarfile = f'{S3_DIR}/{telemetry}-{hostname}-{timestamp}.tar'
if xz:
tarfile = tarfile + '.xz'
print(f'processing {filedir}, tar {tarfile}')
tar_dir(filedir, tarfile, xz=xz)
s3_copy(S3_DIR)
schedule.run_pending()
time.sleep(60)


if __name__ == '__main__':
Expand Down

0 comments on commit cddb915

Please sign in to comment.