def __init__(self, execution_id, user: User, execution_service: ExecutionService, result_folder, file_storage) -> None: self.execution_id = execution_id self.execution_service = execution_service self.config = self.execution_service.get_config(execution_id, user) self.result_files_paths = self._get_paths(execution_id, self._is_post_finish_path) self.inline_image_paths = self._get_paths(execution_id, self._is_inline_image_path) self.prepared_files = {} self.result_files = [] self.inline_images = {} self.inline_image_listeners = [] if not self.result_files_paths and not self.inline_image_paths: return self.output_stream = self.execution_service.get_anonymized_output_stream(execution_id) execution_owner = execution_service.get_owner(execution_id) self.download_folder = file_storage.prepare_new_folder(execution_owner, result_folder) LOGGER.info('Created download folder for ' + execution_owner + ': ' + self.download_folder) if self.result_files_paths: execution_service.add_finish_listener(self._execution_finished, execution_id) if self.inline_image_paths: self._listen_for_images()
def subscribe(self, execution_service: ExecutionService): download_feature = self def execution_finished(execution_id): config = execution_service.get_config(execution_id) if not download_feature._is_downloadable(config): return output_stream = execution_service.get_anonymized_output_stream(execution_id) output_stream_data = read_until_closed(output_stream) script_output = ''.join(output_stream_data) parameter_values = execution_service.get_user_parameter_values(execution_id) owner = execution_service.get_owner(execution_id) downloadable_files = download_feature._prepare_downloadable_files( config, script_output, parameter_values, owner) download_feature._execution_download_files[execution_id] = downloadable_files execution_service.add_finish_listener(execution_finished)