def download_thread(run_: Run) -> None: """The function executed by the download thread """ run_copy = deepcopy(run_) for i, download_ in enumerate(downloads): run_.download_status = float(i) / len(downloads) run_copy.downloads = [download_] self.download(run_copy) run_.download_status = 1.0
def submit(self, run: Run) -> bool: # copy execution script to remote runscript_name = f'rynner_exec_{run.job_name}' local_script_path = os.path.expanduser("~") local_script_path = os.path.join( local_script_path, run.namespace, run.submission_id) if run.namespace else os.path.join( local_script_path, run.submission_id) local_script_path = os.path.join(local_script_path, runscript_name) if not os.path.isdir(os.path.split(local_script_path)[0]): os.makedirs(os.path.split(local_script_path)[0]) with open(local_script_path, "w") as file: file.write(run.script) self.provider.channel.push_file(local_script_path, run.remote_dir.as_posix()) # record submission times on remote self._record_time('submit', run, execute=True) # submit run submit_script = (f'{self._record_time("start", run)}; ' f'cd {run.remote_dir.as_posix()}; ' f'./{runscript_name}; ' f'cd ; ' f'{self._record_time("end", run)}') p_ = os.path.join( run.namespace, run.submission_id) if run.namespace else run.submission_id self.provider.channel.script_dir = p_ self.provider.script_dir = os.path.split(local_script_path)[0] job_id = self.provider.submit(submit_script, tasks_per_node=1) if job_id is None: # Failed to submit return False else: # Succesfully submitted run.job_id = job_id run.job_status = self.StatusPending self.save_run_config(run) return True
def create_run(self, script: str, uploads: list[str] = None, downloads: list[str] = None, namespace: str = None, jobname: str = 'rynner') -> Run: if not uploads: uploads = [] if not downloads: downloads = [] uid = str(uuid.uuid1()) run = Run(submission_id=uid, job_name=jobname, upload_time=0, remote_dir=self._remote_dir(namespace, uid), uploads=uploads, downloads=downloads, script=script, upload_status=0, job_status=self.StatusPending, namespace='rynner', download_status=0, job_id=None) return run
def upload(self, run: Run) -> None: """Uploads files using provider channel. """ uploads = run.uploads for upload in uploads: src, dest = self._parse_path(upload) dest = run.remote_dir.joinpath(dest).as_posix() self.provider.channel.push_file(src, dest) run.upload_time = time.time()
def start_download(self, run: Run) -> None: """Spawn a thread to download the files in the download list. Update a report of the current state of the process. """ downloads = [] for download in run.downloads: downloads += self.list_remote_files(run, download[0], download[1]) def download_thread(run_: Run) -> None: """The function executed by the download thread """ run_copy = deepcopy(run_) for i, download_ in enumerate(downloads): run_.download_status = float(i) / len(downloads) run_copy.downloads = [download_] self.download(run_copy) run_.download_status = 1.0 run.download_status = 0 thread = threading.Thread(target=download_thread, args=(run, )) thread.start()
def start_upload(self, run: Run) -> None: """Spawn a thread to upload the files in the upload list. Update a report of the current state of the process. """ uploads = [] for upload in run.uploads: uploads += self.list_local_files(run, upload[0], upload[1]) def upload_thread(run_: Run) -> None: """The function executed by the download thread """ run_copy = deepcopy(run_) for i, upload_ in enumerate(uploads): run_.upload_status = float(i) / len(uploads) run_copy.uploads = [upload_] self.upload(run_copy) run_.upload_status = 1.0 run.upload_status = 0 thread = threading.Thread(target=upload_thread, args=(run, )) thread.start()
def cancel(self, run: Run) -> None: self._record_time('cancel', run) run.job_id = self.provider.cancel(run.script, 1) run.job_status = self.StatusCancelled self.save_run_config(run)