Skip to content

Commit

Permalink
add generate_computed_file management command
Browse files Browse the repository at this point in the history
  • Loading branch information
avrohomgottlieb committed Oct 15, 2024
1 parent 19bd10e commit 77ae571
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions api/scpca_portal/management/commands/generate_computed_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import logging
from typing import Dict

from django.core.management.base import BaseCommand

from scpca_portal import loader
from scpca_portal.models import Project, Sample

logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())


class Command(BaseCommand):
help = """
This command is meant to be called as an entrypoint to AWS Batch Fargate job instance.
Individual files are computed according:
- To the project or sample id
- An appropriate corresponding download config
When computation is completed, files are uploaded to S3, and the job is marked as completed.
At which point the instance which generated this computed file will receive a new job
from the job queue and begin computing the next file.
"""

def add_arguments(self, parser):
parser.add_argument("--project-id", type=str)
parser.add_argument("--sample-id", type=str)
parser.add_argument("--download-config", type=dict)

def handle(self, *args, **kwargs):
self.generate_computed_file(**kwargs)

def generate_computed_file(
self,
project_id: str,
sample_id: str,
download_config: Dict,
**kwargs,
) -> None:
"""Generates a project's computed files according predetermined download configurations"""
loader.prep_data_dirs()

project = Project.objects.filter(scpca_id=project_id).first() if project_id else None
sample = Sample.objects.filter(scpca_id=sample_id).first() if sample_id else None

loader.generate_computed_file(
download_config=download_config, project=project, sample=sample
)

0 comments on commit 77ae571

Please sign in to comment.