-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1ab67b
commit 78d3286
Showing
9 changed files
with
54 additions
and
43 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
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
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
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 |
---|---|---|
@@ -1,14 +1,52 @@ | ||
from base.utils.gcloud import generate_download_signed_url_v4 | ||
import os | ||
import time | ||
|
||
from datetime import timedelta | ||
from flask import jsonify, Blueprint | ||
|
||
from base.config import config | ||
from base.constants import BAM_BAI_DOWNLOAD_SCRIPT_NAME | ||
from base.views.api.api_strain import query_strains | ||
from base.utils.cache import delete_expired_cache | ||
|
||
maintenance_bp = Blueprint('maintenance', | ||
__name__) | ||
|
||
|
||
@maintenance_bp.route('/cleanup_cache', methods=['POST']) | ||
@maintenance_bp.route('/cleanup_cache', methods=['GET']) | ||
def cleanup_cache(): | ||
result = delete_expired_cache() | ||
response = jsonify({"result": result}) | ||
response.status_code = 200 | ||
return response | ||
|
||
@maintenance_bp.route('/create_bam_bai_download_script', methods=['GET']) | ||
def create_bam_bai_download_script(): | ||
''' Generates signed downloads urls for every sequenced strain and creates a script to download them ''' | ||
filename = f'base/{BAM_BAI_DOWNLOAD_SCRIPT_NAME}' | ||
if os.path.exists(filename): | ||
os.remove(filename) | ||
f = open(filename, "a") | ||
|
||
expiration = timedelta(days=7) | ||
strain_listing = query_strains(release=config["DATASET_RELEASE"], is_sequenced=True) | ||
|
||
for strain in strain_listing: | ||
f.write(f'\n\n# Strain: {strain}') | ||
|
||
bam_path = 'bam/{}.bam'.format(strain) | ||
bam_signed_url = generate_download_signed_url_v4(bam_path, expiration=expiration) | ||
if bam_signed_url: | ||
f.write('\nwget "{}"'.format(bam_signed_url)) | ||
|
||
bai_path = 'bam/{}.bam.bai'.format(strain) | ||
bai_signed_url = generate_download_signed_url_v4(bai_path, expiration=expiration) | ||
if bai_signed_url: | ||
f.write('\nwget "{}"'.format(bai_signed_url)) | ||
|
||
f.close() | ||
|
||
response = jsonify({}) | ||
response.status_code = 200 | ||
return response |
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