File tree Expand file tree Collapse file tree 6 files changed +13
-18
lines changed Expand file tree Collapse file tree 6 files changed +13
-18
lines changed Original file line number Diff line number Diff line change @@ -16,9 +16,9 @@ def put(self, download: DescribeDownload):
1616 session .add (download )
1717 session .commit ()
1818
19- def get (self , job_id : str ) -> Optional [DescribeDownload ]:
19+ def get (self , download_id : str ) -> Optional [DescribeDownload ]:
2020 with self .session () as session :
21- download = session .query (Download ).filter (Download .job_id == job_id ).first ()
21+ download = session .query (Download ).filter (Download .download_id == download_id ).first ()
2222
2323 if download :
2424 return DescribeDownload .from_orm (download )
@@ -45,13 +45,14 @@ def __init__(self, db_url: str):
4545 self .record_manager = DownloadRecordManager (db_url = db_url )
4646 self .queue = Queue ()
4747
48- def download_from_staging (self , job_id : str ):
48+ def download_from_staging (self , job_id : str , redownload : bool ):
4949 download_initiated_time = get_utc_timestamp ()
5050 download_id = generate_uuid ()
5151 download = DescribeDownload (
5252 job_id = job_id ,
5353 download_id = download_id ,
5454 download_initiated_time = download_initiated_time ,
55+ redownload = redownload ,
5556 )
5657 self .record_manager .put (download )
5758 self .queue .put (download )
Original file line number Diff line number Diff line change @@ -23,11 +23,11 @@ def __init__(
2323 async def process_download_queue (self ):
2424 while not self .download_manager .queue .empty ():
2525 download = self .download_manager .queue .get ()
26- cache = self .download_manager .record_manager .get (download .job_id )
27- if not cache or not download :
26+ download_record = self .download_manager .record_manager .get (download .download_id )
27+ if not download_record :
2828 continue
29- await self .job_files_manager .copy_from_staging (cache .job_id )
30- self .download_manager .record_manager . delete_download (cache .download_id )
29+ await self .job_files_manager .copy_from_staging (download .job_id , download . redownload )
30+ self .download_manager .delete_download (download .download_id )
3131
3232 async def start (self ):
3333 self .download_manager .populate_queue ()
Original file line number Diff line number Diff line change @@ -165,6 +165,7 @@ def _download_from_staging(self, job_id: str):
165165 job_id = job_id ,
166166 download_id = download_id ,
167167 download_initiated_time = download_initiated_time ,
168+ redownload = True ,
168169 )
169170 with self .db_session () as session :
170171 download_record = Download (** download .dict ())
Original file line number Diff line number Diff line change @@ -394,16 +394,8 @@ def get(self):
394394
395395
396396class FilesDownloadHandler (ExtensionHandlerMixin , APIHandler ):
397- # _job_files_manager = None
398397 _download_from_staging = None
399398
400- # @property
401- # def job_files_manager(self):
402- # if not self._job_files_manager:
403- # self._job_files_manager = self.settings.get("job_files_manager", None)
404-
405- # return self._job_files_manager
406-
407399 @property
408400 def download_from_staging (self ):
409401 if not self ._download_from_staging :
@@ -413,10 +405,9 @@ def download_from_staging(self):
413405
414406 @authenticated
415407 async def get (self , job_id ):
416- # redownload = self.get_query_argument("redownload", False)
408+ redownload = self .get_query_argument ("redownload" , False )
417409 try :
418- # await self.job_files_manager.copy_from_staging(job_id=job_id, redownload=redownload)
419- self .download_from_staging (job_id )
410+ self .download_from_staging (job_id , redownload )
420411 except Exception as e :
421412 self .log .exception (e )
422413 raise HTTPError (500 , str (e )) from e
Original file line number Diff line number Diff line change @@ -300,6 +300,7 @@ class DescribeDownload(BaseModel):
300300 job_id : str
301301 download_id : str
302302 download_initiated_time : int
303+ redownload : bool
303304
304305 class Config :
305306 orm_mode = True
Original file line number Diff line number Diff line change @@ -116,6 +116,7 @@ class Download(Base):
116116 job_id = Column (String (36 ), primary_key = True )
117117 download_id = Column (String (36 ), primary_key = True )
118118 download_initiated_time = Column (Integer )
119+ redownload = Column (Boolean , default = False )
119120
120121
121122def create_tables (db_url , drop_tables = False ):
You can’t perform that action at this time.
0 commit comments