Example #1
0
 def send_inline_image(self, original_path, download_path):
     self.safe_write(
         wrap_to_server_event(
             'inline-image', {
                 'output_path': original_path,
                 'download_url': self.prepare_download_url(download_path)
             }))
Example #2
0
    def _send_parameter_changed(self, parameter):
        external_param = parameter_to_external(parameter)
        if external_param is None:
            return

        self.safe_write(
            wrap_to_server_event('parameterChanged', external_param))
Example #3
0
        def finished():
            try:
                downloadable_files = file_download_feature.get_downloadable_files(
                    execution_id)

                for file in downloadable_files:
                    filename = os.path.basename(file)
                    url_path = web_socket.prepare_download_url(file)

                    web_socket.safe_write(
                        wrap_to_server_event('file', {
                            'url': url_path,
                            'filename': filename
                        }))
            except:
                LOGGER.exception('Could not prepare downloadable files')

            connection = web_socket.ws_connection
            if (connection is not None) and (hasattr(connection,
                                                     'ping_callback')):
                # we need to stop callback explicitly and as soon as possible, to avoid sending ping after close
                connection.ping_callback.stop()

            output_stream.wait_close(timeout=5)
            web_socket.ioloop.add_callback(web_socket.close, code=1000)
Example #4
0
    def open(self, user, execution_id):
        auth = self.application.auth
        if not auth.is_authenticated(self):
            return None

        execution_service = self.application.execution_service

        try:
            self.executor = execution_service.get_active_executor(
                execution_id, get_user(self))
        except Exception as e:
            self.handle_exception_on_open(e)
            return

        self.ioloop = tornado.ioloop.IOLoop.current()

        self.write_message(wrap_to_server_event('input', 'your input >>'))

        user_id = identify_user(self)

        output_stream = execution_service.get_raw_output_stream(
            execution_id, user_id)
        pipe_output_to_http(output_stream, self.safe_write)

        file_download_feature = self.application.file_download_feature
        web_socket = self

        def finished():
            try:
                downloadable_files = file_download_feature.get_downloadable_files(
                    execution_id)

                for file in downloadable_files:
                    filename = os.path.basename(file)
                    url_path = web_socket.prepare_download_url(file)

                    web_socket.safe_write(
                        wrap_to_server_event('file', {
                            'url': url_path,
                            'filename': filename
                        }))
            except:
                LOGGER.exception('Could not prepare downloadable files')

            connection = web_socket.ws_connection
            if (connection is not None) and (hasattr(connection,
                                                     'ping_callback')):
                # we need to stop callback explicitly and as soon as possible, to avoid sending ping after close
                connection.ping_callback.stop()

            output_stream.wait_close(timeout=5)
            web_socket.ioloop.add_callback(web_socket.close, code=1000)

        file_download_feature.subscribe_on_inline_images(
            execution_id, self.send_inline_image)

        execution_service.add_finish_listener(finished, execution_id)
Example #5
0
    def _prepare_and_send_model(self,
                                *,
                                parameter_values=None,
                                external_id=None,
                                event_type):
        config_model = yield self._prepare_model(self.config_name,
                                                 self.user,
                                                 parameter_values,
                                                 skip_invalid_parameters=True)
        if not config_model:
            return

        self._set_model(config_model)

        new_config = external_model.config_to_external(config_model,
                                                       self.config_id,
                                                       external_id)
        self.safe_write(wrap_to_server_event(event_type, new_config))
Example #6
0
 def on_next(self, output):
     write_callback(wrap_to_server_event('output', output))
Example #7
0
 def _create_event(self, event_type, data):
     data['clientStateVersion'] = self._latest_client_state_version
     return wrap_to_server_event(event_type=event_type, data=data)
Example #8
0
 def on_remove(self, parameter):
     socket.safe_write(
         wrap_to_server_event('parameterRemoved', parameter.name))
Example #9
0
 def on_add(self, parameter, index):
     socket.safe_write(
         wrap_to_server_event('parameterAdded',
                              parameter_to_external(parameter)))
     socket._subscribe_on_parameter(parameter)