示例#1
0
    def poll_until_complete(self,
                            interval=1000 * 5,
                            timeout=1000 * 60 * 120,
                            callback=None):
        "Keep polling for command state until it has finished running"
        self._complete_callback = callback
        if not self.finished():

            def _poll():
                if state.connected and not self._error:
                    self._fetch_value()
                    if not self.finished():
                        self._check_status()
                    else:
                        if self._complete_callback:
                            self._complete_callback(self)

                    f = self.finished()
                    if f:
                        state.commands.remove(self)
                    return f
                return False

            state.commands.add(self)
            utils.poll_func(_poll, timeout, interval)
        else:
            self._fetch_value()
            if self._complete_callback:
                self._complete_callback(self)
示例#2
0
    def __init__(self, name="webclient", session="", namespace=""):
        self.clients.append(self)
        self.session_id = utils.storage.get("session_id")
        if not self.session_id:
            self.session_id = utils.random_string(10)
            utils.storage.set("session_id", self.session_id)
        self.socket_url = location.protocol + '//' + location.hostname + ':' + location.port + namespace
        self.socket = io(self.socket_url, {'transports': ['websocket']})
        self.socket.on("command", self.on_command)
        self.socket.on("server_call", self.on_server_call)
        self.socket.on("exception", self.on_error)
        self.socket.on("connect", self.on_connect)
        self.socket.on("disconnect", self.on_disconnect)

        self.commands = {
            'connect': 1,
            'reconnect': 2,
            'disconnect': 3,
            'status': 4,
            'handshake': 5,
            'rehandshake': 6
        }
        self.command_callbacks = {}

        self.namespace = namespace
        self.session = session
        self.name = name
        self._reconnecting = False
        self._connection_status = True
        self._disconnected_once = False
        self._initial_socket_connection = False
        self._socket_connection = False
        self._response_cb = {}
        self._first_connect = True
        self._msg_queue = []
        self._last_msg = None
        self._cmd_status = {}
        self._cmd_status_c = 0
        self._retries = None
        self._poll_interval = 5
        self._poll_timeout = 1000 * 60 * 120
        self._last_retry = __new__(Date()).getTime()
        self._prev_retry_interval = 0

        self.polling = False
        if not Client.polling:
            utils.poll_func(self.connection, self._poll_timeout,
                            self._poll_interval * 1000)
            self.polling = True
            Client.polling = True
示例#3
0
    def poll_progress(self,
                      interval=1000 * 3,
                      timeout=1000 * 60 * 120,
                      callback=None):
        "Keep polling for command progress until it has finished running"
        self._progress_callback = callback
        if not self.finished():

            def _poll():
                if state.connected and not self._error:
                    if not self.finished():
                        self._check_status()
                    self._fetch_progress()
                    if self._progress_callback:
                        self._progress_callback(self)
                    f = self.finished()
                    return f
                return False

            utils.poll_func(_poll, timeout, interval)
        else:
            self._fetch_progress()
            if self._progress_callback:
                self._progress_callback(self)