|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the MIT License. See License.txt in the project root for license information. |
| 3 | + |
| 4 | +#include "../funcgrpc/func_bidi_reactor.h" |
| 5 | +#include "../funcgrpc/func_perf_marker.h" |
| 6 | +#include "../funcgrpc/funcgrpc.h" |
| 7 | +#include "appconfig.h" |
| 8 | +#include <boost/program_options.hpp> |
| 9 | +#include <exception> |
| 10 | +#include <iostream> |
| 11 | +#include <limits.h> |
| 12 | +#include <string> |
| 13 | + |
| 14 | +using namespace std; |
| 15 | +using namespace funcgrpc; |
| 16 | +namespace po = boost::program_options; |
| 17 | + |
| 18 | +unique_ptr<funcgrpc::GrpcWorkerStartupOptions> getWorkerStartupOptions(int argc, char *const *argv); |
| 19 | + |
| 20 | +int main(int argc, char *argv[]) |
| 21 | +{ |
| 22 | + funcgrpc::Log::Init(); |
| 23 | + FUNC_LOG_INFO("Starting FunctionsNetHost main.Build:{}", FunctionsNetHost_VERSION); |
| 24 | + |
| 25 | + try |
| 26 | + { |
| 27 | + auto pOptions = getWorkerStartupOptions(argc, argv); |
| 28 | + auto pApplication = std::make_unique<NativeHostApplication>(); |
| 29 | + auto worker = std::make_unique<FunctionBidiReactor>(pOptions.get(), pApplication.get()); |
| 30 | + Status status = worker->Await(); |
| 31 | + |
| 32 | + if (!status.ok()) |
| 33 | + { |
| 34 | + FUNC_LOG_ERROR("Rpc failed. error_message:{}", status.error_message()); |
| 35 | + } |
| 36 | + } |
| 37 | + catch (const std::exception &ex) |
| 38 | + { |
| 39 | + FUNC_LOG_ERROR("Caught unknown exception.{}", ex.what()); |
| 40 | + } |
| 41 | + catch (...) |
| 42 | + { |
| 43 | + FUNC_LOG_ERROR("Caught unknown exception."); |
| 44 | + } |
| 45 | + |
| 46 | + return 0; |
| 47 | +} |
| 48 | + |
| 49 | +unique_ptr<GrpcWorkerStartupOptions> getWorkerStartupOptions(int argc, char *const *argv) |
| 50 | +{ |
| 51 | + FuncPerfMarker marker("BuildWorkerStartupOptions"); |
| 52 | + |
| 53 | + po::options_description desc("Allowed options"); |
| 54 | + desc.add_options()("help", "sample usage: FunctionsNetHost --host <endpoint> --port <port> --workerid <workerid> " |
| 55 | + "--requestid <requestid> --grpcmaxrequestlength <maxrequestlength>")( |
| 56 | + "host", boost::program_options::value<string>(), |
| 57 | + "Address of grpc server")("port", po::value<int>(), "Port number of grpc server connection")( |
| 58 | + "workerId", boost::program_options::value<string>(), |
| 59 | + "Worker id")("requestId", boost::program_options::value<string>(), |
| 60 | + "Request id")("grpcMaxMessageLength", po::value<int>()->default_value(INT_MAX), |
| 61 | + "Max length for grpc messages. Default is INT_MAX"); |
| 62 | + |
| 63 | + po::variables_map vm; |
| 64 | + po::store(po::parse_command_line(argc, argv, desc), vm); |
| 65 | + po::notify(vm); |
| 66 | + |
| 67 | + auto options = make_unique<GrpcWorkerStartupOptions>(); |
| 68 | + |
| 69 | + if (vm.count("host")) |
| 70 | + { |
| 71 | + options->host = vm["host"].as<string>(); |
| 72 | + } |
| 73 | + if (vm.count("port")) |
| 74 | + { |
| 75 | + options->port = vm["port"].as<int>(); |
| 76 | + } |
| 77 | + if (vm.count("workerId")) |
| 78 | + { |
| 79 | + options->workerId = vm["workerId"].as<string>(); |
| 80 | + } |
| 81 | + if (vm.count("requestId")) |
| 82 | + { |
| 83 | + options->requestId = vm["requestId"].as<string>(); |
| 84 | + } |
| 85 | + if (vm.count("grpcMaxMessageLength")) |
| 86 | + { |
| 87 | + options->grpcMaxMessageLength = vm["grpcMaxMessageLength"].as<int>(); |
| 88 | + } |
| 89 | + |
| 90 | + return options; |
| 91 | +} |
0 commit comments