azure_functions/commands/
run.rs1use crate::{registry::Registry, worker::Worker};
2use clap::{App, Arg, ArgMatches, SubCommand};
3
4pub struct Run<'a> {
5 pub host: &'a str,
6 pub port: u16,
7 pub worker_id: &'a str,
8}
9
10impl<'a> Run<'a> {
11 pub fn create_subcommand<'b>() -> App<'a, 'b> {
12 SubCommand::with_name("run")
13 .about("Runs the Rust language worker.")
14 .arg(
15 Arg::with_name("host")
16 .long("host")
17 .value_name("HOST")
18 .help("The hostname of the Azure Functions Host.")
19 .required(true),
20 )
21 .arg(
22 Arg::with_name("port")
23 .long("port")
24 .value_name("PORT")
25 .help("The port of the Azure Functions Host.")
26 .required(true),
27 )
28 .arg(
29 Arg::with_name("worker_id")
30 .long("workerId")
31 .value_name("WORKER_ID")
32 .help("The worker ID to use when registering with the Azure Functions Host.")
33 .required(true),
34 )
35 .arg(
36 Arg::with_name("request_id")
37 .long("requestId")
38 .value_name("REQUEST_ID")
39 .help("The request ID to use when communicating with the Azure Functions Host.")
40 .hidden(true)
41 .required(true),
42 )
43 .arg(
44 Arg::with_name("max_message_length")
45 .long("grpcMaxMessageLength")
46 .value_name("MAXIMUM")
47 .help("The maximum message length to use for gRPC messages."),
48 )
49 }
50
51 pub fn execute(&self, registry: Registry<'static>) -> Result<(), String> {
52 ctrlc::set_handler(|| {}).expect("failed setting SIGINT handler");
53
54 Worker::run(self.host, self.port, self.worker_id, registry);
55
56 Ok(())
57 }
58}
59
60impl<'a> From<&'a ArgMatches<'a>> for Run<'a> {
61 fn from(args: &'a ArgMatches<'a>) -> Self {
62 Run {
63 host: args.value_of("host").expect("A host is required."),
64 port: args
65 .value_of("port")
66 .map(|port| port.parse::<u16>().expect("Invalid port number"))
67 .expect("A port number is required."),
68 worker_id: args
69 .value_of("worker_id")
70 .expect("A worker id is required."),
71 }
72 }
73}