def emit(self, record): """Emit record to slack channel using pycurl to avoid recurrence event logging (log logged record) """ if record.message.startswith(MESSAGE): # avoid cyrcular emit return cfg = self.app.config managers = cfg['SLACK_LINK_NAMES'] text = '' data = {} if managers: text = ' '.join(('@%s' % m for m in managers)) text = '%s\n\n' % text data['link_names'] = 1 context_factory = cfg['LOG_CONTEXT_FACTORY'] data['text'] = text if context_factory: ctx = context_factory(self) data['text'] += "\n" + context_text_formatter(ctx) data['text'] += "```\n%s\n```" % self.format(record) sessions = self.app.http() response = sessions.post(self.webhook_url, data=json.dumps(data)) if isawaitable(response): ensure_future(self._emit(response), loop=sessions._loop) else: sessions._loop.call_soon(self._raise_error, response)
def __call__(self, environ, start_response): uri = environ['RAW_URI'] if uri == environ.get('HTTP_HOST'): raise Http404 logger.debug('new request for %r' % uri) if not uri or uri.startswith('/'): # No proper uri, raise 404 raise HttpException(status=404) response = TunnelResponse(self, environ, start_response) ensure_future(response.request()) return response.future
def __call__(self, environ, start_response): uri = environ['RAW_URI'] if uri == environ.get('HTTP_HOST'): raise Http404 logger.debug('new request for %r' % uri) if not uri or uri.startswith('/'): # No proper uri, raise 404 raise HttpException(status=404) response = TunnelResponse(self, environ, start_response) ensure_future(response.request()) return response.future
def _check_queue(self): # Run in the main greenlet of the event-loop thread if not self._adjust_greenlet_count(): self.logger.debug('No greenlet available') return self._loop.call_soon(self._check_queue) try: task = self._queue.pop() except IndexError: return ensure_future(self._green_task(self._available.pop(), task), loop=self._loop)
def setup(self, environ): '''Called once only to setup the WSGI application handler. Check :ref:`lazy wsgi handler <wsgi-lazy-handler>` section for further information. ''' request = wsgi_request(environ) cfg = request.cache.cfg loop = request.cache._loop self.store = create_store(cfg.data_store, loop=loop) pubsub = self.store.pubsub(protocol=Protocol()) channel = '%s_webchat' % self.name ensure_future(pubsub.subscribe(channel), loop=loop) return WsgiHandler([Router('/', get=self.home_page), WebSocket('/message', Chat(pubsub, channel)), Router('/rpc', post=Rpc(pubsub, channel), response_content_types=JSON_CONTENT_TYPES)], [AsyncResponseMiddleware, GZipMiddleware(min_length=20)])
def start(arb): ensure_future(app())
def start(arbiter, **kw): ensure_future(app(arbiter))