-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add upload_fluxiae_to_pilotage command and cron schedule
Added pilotage_s3_client configuration with new environment variables Fix prevent globbing in bash script Restore populate_metabase_fluxiae in the import-iae.sh script Remove PILOTAGE_S3_FLUX_IAE_OBJECT_KEY setting Replace tdqm in upload command Rename upload_data_to_pilotage command Fix asp_riae_shared_bucket directory Added upload_to_pilotage.sh Remove manual upload_data_to_pilotage usage Fix double-quoting when referencing ROOT in bash script
- Loading branch information
1 parent
2c04ca2
commit 513ba00
Showing
6 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash -l | ||
|
||
cd "$APP_HOME" || exit | ||
|
||
FLUX_IAE_FILE_GLOB='fluxIAE_*.tar.gz' | ||
|
||
FLUX_IAE_FILE=$(find asp_riae_shared_bucket/ -name "$FLUX_IAE_FILE_GLOB" -type f -mtime -5) | ||
if [[ ! -f "$FLUX_IAE_FILE" ]]; then | ||
echo "Missing the flux IAE file." | ||
exit 0 | ||
fi | ||
|
||
/bin/bash "$ROOT"/clevercloud/run_management_command.sh upload_data_to_pilotage "$FLUX_IAE_FILE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
itou/metabase/management/commands/upload_data_to_pilotage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
The FluxIAE file contains data used by les emplois and is uploaded to us directly by a supporting organization. | ||
The same file is also parsed by the Pilotage, shared via an S3 bucket. | ||
This command uploads the file from where it has been stored to the S3 bucket for sharing. | ||
""" | ||
|
||
import os | ||
|
||
from django.conf import settings | ||
from django.core.management.base import CommandError | ||
|
||
from itou.utils.command import BaseCommand | ||
from itou.utils.storage.s3 import pilotage_s3_client | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Upload FluxIAE to S3 for sharing." | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument("filename", type=str, help="The name of the FluxIAE import file in the import directory") | ||
|
||
def handle(self, filename, *args, **options): | ||
# Ran from the home directory on production. | ||
filepath = os.path.join("asp_riae_shared_bucket", filename) | ||
# Confirm the file exists. | ||
if not os.path.exists(filepath): | ||
raise CommandError(f"For upload_data_to_pilotage to work, a file must exist at given file path {filepath}") | ||
|
||
# Upload the data to the S3. | ||
file_size = os.stat(filepath).st_size | ||
bytes_transferred = 0 | ||
previous_progress = 0 | ||
|
||
def log_progress(chunk_size): | ||
"""Logs to console or logs the progress of byte transfer""" | ||
nonlocal bytes_transferred | ||
nonlocal previous_progress | ||
|
||
bytes_transferred += chunk_size | ||
progress = int((bytes_transferred / file_size) * 100) | ||
if progress != previous_progress: | ||
print(f"{bytes_transferred}/{file_size} bytes transferred ({progress}%).") | ||
previous_progress = progress | ||
|
||
pilotage_s3_client().upload_file( | ||
Filename=filepath, | ||
Bucket=settings.PILOTAGE_DATASTORE_S3_BUCKET_NAME, | ||
Key=filename, | ||
Callback=lambda chunk_size: log_progress(chunk_size), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters