@access.cookie
    @access.token
    @describeRoute(
        Description('Stream notifications for a given user via the SSE '
                    'protocol.')
        .notes('This uses long-polling to keep the connection open for '
               'several minutes at a time (or longer) and should be requested '
               'with an EventSource object or other SSE-capable client. '
               '<p>Notifications are returned within a few seconds of when '
               'they occur.  When no notification occurs for the timeout '
               'duration, the stream is closed. '
               '<p>This connection can stay open indefinitely long.')
        .param('timeout', 'The duration without a notification before the '
               'stream is closed.', dataType='integer', required=False)
        .errorResponse()
        .errorResponse('You are not logged in.', 403)
    )
    def stream(self, params):
        user = self.getCurrentUser()
        token = self.getCurrentToken()

        cherrypy.response.headers['Content-Type'] = 'text/event-stream'
        cherrypy.response.headers['Cache-Control'] = 'no-cache'

        timeout = int(params.get('timeout', DEFAULT_STREAM_TIMEOUT))

        def streamGen():
            lastUpdate = None
            start = time.time()
            wait = MIN_POLL_INTERVAL
            while cherrypy.engine.state == cherrypy.engine.states.STARTED:
                wait = min(wait + MIN_POLL_INTERVAL, MAX_POLL_INTERVAL)
                for event in self.model('notification').get(
                        user, lastUpdate, token=token):
                    if lastUpdate is None or event['updated'] > lastUpdate:
                        lastUpdate = event['updated']
                    wait = MIN_POLL_INTERVAL
                    start = time.time()
                    yield sseMessage(event)
                if time.time() - start > timeout:
                    break

                time.sleep(wait)
        return streamGen
Streams notifications using the server-sent events protocol. Closes
dataset/ETHPy150Open girder/girder/girder/api/v1/notification.py/Notification.stream