Example #1
0
 def init_web_app(self):
     self.web_application = chronograph_webapp
     self.web_application.chronograph = self
     location = self.config['main'].get('web_app')
     if ':' in str(location):
         if not location.startswith('//'):
             location = "//{}".format(location)
         o = urlparse(location)
         self.server = WSGIServer(get_lisener(o.port, o.hostname),
                                  self.web_application,
                                  spawn=100)
     else:
         self.server = WSGIServer(get_lisener(location),
                                  self.web_application,
                                  spawn=100)
     self.server.start()
def run_server(auction, mapping_expire_time, logger, timezone='Europe/Kiev', bids_form=BidsForm,
               bids_handler=BidsHandler, form_handler=form_handler, cookie_path=AUCTION_SUBPATH):
    app = initialize_application()
    add_url_rules(app)
    app.config.update(auction.worker_defaults)
    # Replace Flask custom logger
    app.logger_name = logger.name
    app._logger = logger
    app.config['timezone'] = tz(timezone)
    app.config['SESSION_COOKIE_PATH'] = '/{}/{}'.format(cookie_path, auction.context['auction_doc_id'])
    app.config['SESSION_COOKIE_NAME'] = 'auction_session'
    app.oauth = OAuth(app)
    app.gsm = getGlobalSiteManager()
    app.context = app.gsm.queryUtility(IContext)
    app.bids_form = bids_form
    app.bids_handler = bids_handler()
    app.form_handler = form_handler
    app.remote_oauth = app.oauth.remote_app(
        'remote',
        consumer_key=app.config['OAUTH_CLIENT_ID'],
        consumer_secret=app.config['OAUTH_CLIENT_SECRET'],
        request_token_params={'scope': 'email'},
        base_url=app.config['OAUTH_BASE_URL'],
        access_token_url=app.config['OAUTH_ACCESS_TOKEN_URL'],
        authorize_url=app.config['OAUTH_AUTHORIZE_URL']
    )

    @app.remote_oauth.tokengetter
    def get_oauth_token():
        return session.get('remote_oauth')
    os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = 'true'

    # Start server on unused port
    request_id = generate_request_id()

    listener = get_lisener(auction.worker_defaults["STARTS_PORT"],
                          host=auction.worker_defaults.get("WORKER_BIND_IP", ""))
    app.logger.info(
        "Start server on {0}:{1}".format(*listener.getsockname()),
        extra={"JOURNAL_REQUEST_ID": request_id}
    )
    server = WSGIServer(listener, app,
                        log=_LoggerStream(logger),
                        handler_class=AuctionsWSGIHandler)
    server.start()
    # Set mapping
    mapping_value = "http://{0}:{1}/".format(*listener.getsockname())
    create_mapping(auction.worker_defaults,
                   auction.context['auction_doc_id'],
                   mapping_value)
    app.logger.info("Server mapping: {} -> {}".format(
        auction.context['auction_doc_id'],
        mapping_value,
        mapping_expire_time
    ), extra={"JOURNAL_REQUEST_ID": request_id})

    # Spawn events functionality
    spawn(push_timestamps_events, app,)
    spawn(check_clients, app, )
    return server
 def init_web_app(self):
     self.web_application = chronograph_webapp
     self.web_application.chronograph = self
     self.server = WSGIServer(get_lisener(
         self.config['main'].get('web_app'), host="0.0.0.0"),
                              self.web_application,
                              spawn=100)
     self.server.start()
 def init_web_app(self):
     self.web_application = chronograph_webapp
     self.web_application.chronograph = self
     location = self.config['main'].get('web_app')
     if ':' in str(location):
         if not location.startswith('//'):
             location = "//{}".format(location)
         o = urlparse(location)
         self.server = WSGIServer(
             get_lisener(o.port, o.hostname),
             self.web_application,
             spawn=100
         )
     else:
         self.server = WSGIServer(
             get_lisener(location),
             self.web_application,
             spawn=100
         )
     self.server.start()