コード例 #1
0
ファイル: server.py プロジェクト: youyuantech/FogLAMP
    async def _exec_plugin_poll(self) -> None:
        """Executes poll type plugin
        """
        _LOGGER.info('Started South Plugin: {}'.format(self._name))
        try_count = 1

        # pollInterval is expressed in milliseconds
        if int(self._plugin_handle['pollInterval']['value']) <= 0:
            self._plugin_handle['pollInterval']['value'] = '1000'
            _LOGGER.warning(
                'Plugin {} pollInterval must be greater than 0, defaulting to {} ms'
                .format(self._name,
                        self._plugin_handle['pollInterval']['value']))
        sleep_seconds = int(
            self._plugin_handle['pollInterval']['value']) / 1000.0
        _TIME_TO_WAIT_BEFORE_RETRY = sleep_seconds

        while self._plugin and try_count <= _MAX_RETRY_POLL:
            try:
                t1 = self._event_loop.time()
                data = self._plugin.plugin_poll(self._plugin_handle)
                if len(data) > 0:
                    if isinstance(data, list):
                        for reading in data:
                            asyncio.ensure_future(
                                Ingest.add_readings(
                                    asset=reading['asset'],
                                    timestamp=reading['timestamp'],
                                    key=reading['key'],
                                    readings=reading['readings']))
                    elif isinstance(data, dict):
                        asyncio.ensure_future(
                            Ingest.add_readings(asset=data['asset'],
                                                timestamp=data['timestamp'],
                                                key=data['key'],
                                                readings=data['readings']))
                delta = self._event_loop.time() - t1
                # If delta somehow becomes > sleep_seconds, then ignore delta
                sleep_for = sleep_seconds - delta if delta < sleep_seconds else sleep_seconds
                await asyncio.sleep(sleep_for)
            except asyncio.CancelledError:
                pass
            except KeyError as ex:
                try_count = 2
                _LOGGER.exception('Key error plugin {} : {}'.format(
                    self._name, str(ex)))
            except exceptions.QuietError:
                try_count = 2
                await asyncio.sleep(_TIME_TO_WAIT_BEFORE_RETRY)
            except (Exception, RuntimeError,
                    exceptions.DataRetrievalError) as ex:
                try_count = 2
                _LOGGER.error('Failed to poll for plugin {}'.format(
                    self._name))
                _LOGGER.debug('Exception poll plugin {}'.format(str(ex)))
                await asyncio.sleep(_TIME_TO_WAIT_BEFORE_RETRY)

        _LOGGER.warning('Stopped all polling tasks for plugin: {}'.format(
            self._name))
コード例 #2
0
ファイル: server.py プロジェクト: sdauber/FogLAMP
 async def _exec_plugin_poll(self) -> None:
     """Executes poll type plugin
     """
     _LOGGER.info('Started South Plugin: {}'.format(self._name))
     try_count = 1
     while self._plugin and try_count <= _MAX_RETRY_POLL:
         try:
             data = self._plugin.plugin_poll(self._plugin_handle)
             if len(data) > 0:
                 if isinstance(data, list):
                     for reading in data:
                         asyncio.ensure_future(
                             Ingest.add_readings(
                                 asset=reading['asset'],
                                 timestamp=reading['timestamp'],
                                 key=reading['key'],
                                 readings=reading['readings']))
                 elif isinstance(data, dict):
                     asyncio.ensure_future(
                         Ingest.add_readings(asset=data['asset'],
                                             timestamp=data['timestamp'],
                                             key=data['key'],
                                             readings=data['readings']))
             # pollInterval is expressed in milliseconds
             sleep_seconds = int(
                 self._plugin_handle['pollInterval']['value']) / 1000.0
             await asyncio.sleep(sleep_seconds)
             # If successful, then set retry count back to 1, meaning that
             # only in case of 3 successive failures, exit.
             try_count = 1
         except KeyError as ex:
             _LOGGER.exception('Key error plugin {} : {}'.format(
                 self._name, str(ex)))
         except (Exception, RuntimeError,
                 exceptions.DataRetrievalError) as ex:
             try_count += 1
             _LOGGER.exception(
                 'Failed to poll for plugin {}, retry count: {}'.format(
                     self._name, try_count))
             await asyncio.sleep(_TIME_TO_WAIT_BEFORE_RETRY)
     _LOGGER.exception(
         'Max retries exhausted in starting South plugin: {}'.format(
             self._name))
コード例 #3
0
 async def _exec_plugin_poll(self, config) -> None:
     """Executes poll type plugin
     """
     await Ingest.start(self._core_management_host,
                        self._core_management_port)
     max_retry = 3
     try_count = 1
     while True and try_count <= max_retry:
         try:
             data = self._plugin.plugin_poll(self._plugin_handle)
             if len(data) > 0:
                 if isinstance(data, list):
                     for reading in data:
                         asyncio.ensure_future(
                             Ingest.add_readings(
                                 asset=reading['asset'],
                                 timestamp=reading['timestamp'],
                                 key=reading['key'],
                                 readings=reading['readings']))
                 elif isinstance(data, dict):
                     asyncio.ensure_future(
                         Ingest.add_readings(asset=data['asset'],
                                             timestamp=data['timestamp'],
                                             key=data['key'],
                                             readings=data['readings']))
             # pollInterval is expressed in milliseconds
             sleep_seconds = int(config['pollInterval']['value']) / 1000.0
             await asyncio.sleep(sleep_seconds)
             # If successful, then set retry count back to 1, meaning that only in case of 3 successive failures, exit.
             try_count = 1
         except KeyError as ex:
             _LOGGER.exception('Keyerror plugin {} : {}'.format(
                 self._name, str(ex)))
         except Exception as ex:
             try_count += 1
             _LOGGER.exception(
                 'Failed to poll for plugin {}, retry count: {}'.format(
                     self._name, try_count))
             await asyncio.sleep(2)