39
39
UpdateJobDefinition ,
40
40
)
41
41
from jupyter_scheduler .orm import Job , JobDefinition , create_session
42
- from jupyter_scheduler .utils import create_output_directory , create_output_filename
42
+ from jupyter_scheduler .utils import copy_directory , create_output_directory , create_output_filename
43
43
44
44
45
45
class BaseScheduler (LoggingConfigurable ):
@@ -289,7 +289,10 @@ def add_job_files(self, model: DescribeJob):
289
289
mapping = self .environments_manager .output_formats_mapping ()
290
290
job_files = []
291
291
output_filenames = self .get_job_filenames (model )
292
- output_dir = os .path .relpath (self .get_local_output_path (model ), self .root_dir )
292
+ output_dir = self .get_local_output_path (
293
+ input_filename = model .input_filename , job_id = model .job_id , root_dir_relative = True
294
+ )
295
+
293
296
for output_format in model .output_formats :
294
297
filename = output_filenames [output_format ]
295
298
output_path = os .path .join (output_dir , filename )
@@ -316,13 +319,20 @@ def add_job_files(self, model: DescribeJob):
316
319
model .job_files = job_files
317
320
model .downloaded = all (job_file .file_path for job_file in job_files )
318
321
319
- def get_local_output_path (self , model : DescribeJob ) -> str :
322
+ def get_local_output_path (
323
+ self , input_filename : str , job_id : str , root_dir_relative : Optional [bool ] = False
324
+ ) -> str :
320
325
"""Returns the local output directory path
321
326
where all the job files will be downloaded
322
327
from the staging location.
323
328
"""
324
- output_dir_name = create_output_directory (model .input_filename , model .job_id )
325
- return os .path .join (self .root_dir , self .output_directory , output_dir_name )
329
+ output_dir_name = create_output_directory (input_filename , job_id )
330
+ if root_dir_relative :
331
+ return os .path .relpath (
332
+ os .path .join (self .root_dir , self .output_directory , output_dir_name ), self .root_dir
333
+ )
334
+ else :
335
+ return os .path .join (self .root_dir , self .output_directory , output_dir_name )
326
336
327
337
328
338
class Scheduler (BaseScheduler ):
@@ -375,20 +385,10 @@ def copy_input_folder(self, input_uri: str, nb_copy_to_path: str):
375
385
"""Copies the input file along with the input directory to the staging directory"""
376
386
input_dir_path = os .path .dirname (os .path .join (self .root_dir , input_uri ))
377
387
staging_dir = os .path .dirname (nb_copy_to_path )
378
-
379
- # Copy the input file
380
- self .copy_input_file (input_uri , nb_copy_to_path )
381
-
382
- # Copy the rest of the input folder excluding the input file
383
- for item in os .listdir (input_dir_path ):
384
- source = os .path .join (input_dir_path , item )
385
- destination = os .path .join (staging_dir , item )
386
- if os .path .isdir (source ):
387
- shutil .copytree (source , destination )
388
- elif os .path .isfile (source ) and item != os .path .basename (input_uri ):
389
- with fsspec .open (source ) as src_file :
390
- with fsspec .open (destination , "wb" ) as output_file :
391
- output_file .write (src_file .read ())
388
+ copy_directory (
389
+ source_dir = input_dir_path ,
390
+ destination_dir = staging_dir ,
391
+ )
392
392
393
393
def create_job (self , model : CreateJob ) -> str :
394
394
if not model .job_definition_id and not self .file_exists (model .input_uri ):
@@ -439,6 +439,10 @@ def create_job(self, model: CreateJob) -> str:
439
439
staging_paths = staging_paths ,
440
440
root_dir = self .root_dir ,
441
441
db_url = self .db_url ,
442
+ output_dir = self .get_local_output_path (
443
+ input_filename = model .input_filename ,
444
+ job_id = job .job_id ,
445
+ ),
442
446
).process
443
447
)
444
448
p .start ()
@@ -489,6 +493,10 @@ def list_jobs(self, query: ListJobsQuery) -> ListJobsResponse:
489
493
for job in jobs :
490
494
model = DescribeJob .from_orm (job )
491
495
self .add_job_files (model = model )
496
+ if model .package_input_folder :
497
+ model .output_folder = self .get_local_output_path (
498
+ input_filename = model .input_filename , job_id = model .job_id , root_dir_relative = True
499
+ )
492
500
jobs_list .append (model )
493
501
494
502
list_jobs_response = ListJobsResponse (
0 commit comments