Skip to content

Commit 56f095d

Browse files
committed
propagate redownload, use download_id in get download
1 parent 7abdf27 commit 56f095d

File tree

6 files changed

+13
-18
lines changed

6 files changed

+13
-18
lines changed

jupyter_scheduler/download_manager.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ def put(self, download: DescribeDownload):
1717
session.add(download)
1818
session.commit()
1919

20-
def get(self, job_id: str) -> Optional[DescribeDownload]:
20+
def get(self, download_id: str) -> Optional[DescribeDownload]:
2121
with self.session() as session:
22-
download = session.query(Download).filter(Download.job_id == job_id).first()
22+
download = session.query(Download).filter(Download.download_id == download_id).first()
2323

2424
if download:
2525
return DescribeDownload.from_orm(download)
@@ -46,13 +46,14 @@ def __init__(self, db_url: str):
4646
self.record_manager = DownloadRecordManager(db_url=db_url)
4747
self.queue = Queue()
4848

49-
def download_from_staging(self, job_id: str):
49+
def download_from_staging(self, job_id: str, redownload: bool):
5050
download_initiated_time = get_utc_timestamp()
5151
download_id = generate_uuid()
5252
download = DescribeDownload(
5353
job_id=job_id,
5454
download_id=download_id,
5555
download_initiated_time=download_initiated_time,
56+
redownload=redownload,
5657
)
5758
self.record_manager.put(download)
5859
self.queue.put(download)

jupyter_scheduler/download_runner.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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()

jupyter_scheduler/executors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ def _download_from_staging(self, job_id: str):
163163
job_id=job_id,
164164
download_id=download_id,
165165
download_initiated_time=download_initiated_time,
166+
redownload=True,
166167
)
167168
with self.db_session() as session:
168169
download_record = Download(**download.dict())

jupyter_scheduler/handlers.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -395,16 +395,8 @@ def get(self):
395395

396396

397397
class FilesDownloadHandler(ExtensionHandlerMixin, APIHandler):
398-
# _job_files_manager = None
399398
_download_from_staging = None
400399

401-
# @property
402-
# def job_files_manager(self):
403-
# if not self._job_files_manager:
404-
# self._job_files_manager = self.settings.get("job_files_manager", None)
405-
406-
# return self._job_files_manager
407-
408400
@property
409401
def download_from_staging(self):
410402
if not self._download_from_staging:
@@ -414,10 +406,9 @@ def download_from_staging(self):
414406

415407
@authenticated
416408
async def get(self, job_id):
417-
# redownload = self.get_query_argument("redownload", False)
409+
redownload = self.get_query_argument("redownload", False)
418410
try:
419-
# await self.job_files_manager.copy_from_staging(job_id=job_id, redownload=redownload)
420-
self.download_from_staging(job_id)
411+
self.download_from_staging(job_id, redownload)
421412
except Exception as e:
422413
self.log.exception(e)
423414
raise HTTPError(500, str(e)) from e

jupyter_scheduler/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ class DescribeDownload(BaseModel):
301301
job_id: str
302302
download_id: str
303303
download_initiated_time: int
304+
redownload: bool
304305

305306
class Config:
306307
orm_mode = True

jupyter_scheduler/orm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

121122
def create_tables(db_url, drop_tables=False):

0 commit comments

Comments
 (0)