예제 #1
0
def mock_main_server(*args, **kwargs):
    server = grpc.server(futures.ThreadPoolExecutor(1))
    port = server.add_secure_port("localhost:8088",
                                  grpc.local_server_credentials())
    servicer = MockMainServer(*args, **kwargs)
    media_pb2_grpc.add_MediaServicer_to_server(servicer, server)
    server.start()

    try:
        yield port
    finally:
        server.stop(None).wait()
예제 #2
0
def media_session(bearer_token):
    """
    Create a fresh Media API for testing, uses the bearer token for media auth
    """
    media_auth_interceptor = get_media_auth_interceptor(bearer_token)

    with futures.ThreadPoolExecutor(1) as executor:
        server = grpc.server(executor, interceptors=[media_auth_interceptor])
        port = server.add_secure_port("localhost:0", grpc.local_server_credentials())
        servicer = Media()
        media_pb2_grpc.add_MediaServicer_to_server(servicer, server)
        server.start()

        call_creds = grpc.access_token_call_credentials(bearer_token)
        comp_creds = grpc.composite_channel_credentials(grpc.local_channel_credentials(), call_creds)

        try:
            with grpc.secure_channel(f"localhost:{port}", comp_creds) as channel:
                yield media_pb2_grpc.MediaStub(channel)
        finally:
            server.stop(None).wait()
예제 #3
0
    requests_pb2_grpc.add_RequestsServicer_to_server(Requests(), server)
    search_pb2_grpc.add_SearchServicer_to_server(Search(), server)
    threads_pb2_grpc.add_ThreadsServicer_to_server(Threads(), server)

    server.start()

    media_server = grpc.server(
        futures.ThreadPoolExecutor(2),
        interceptors=[
            LoggingInterceptor(),
            get_media_auth_interceptor(
                config.config["MEDIA_SERVER_BEARER_TOKEN"])
        ],
    )
    media_server.add_insecure_port("[::]:1753")
    media_pb2_grpc.add_MediaServicer_to_server(Media(), media_server)
    media_server.start()

    logger.info(
        f"Serving on 1751 (secure), 1752 (auth), 1753 (media), and 1754 (jailed)"
    )

if config.config["ROLE"] in ["scheduler", "all"]:
    scheduler = start_jobs_scheduler()

if config.config["ROLE"] in ["worker", "all"]:
    worker = start_jobs_worker()

logger.info("App waiting for signal...")

signal.pause()