kinetics_parser/
worker.rs1use crate::environment::{parse_environment, Environment};
2use syn::{
3 parse::{Parse, ParseStream},
4 token, Ident, LitBool, LitInt, LitStr,
5};
6
7#[derive(Debug, Clone)]
8pub struct Worker {
9 pub name: Option<String>,
10 pub queue_alias: Option<String>,
11 pub concurrency: i16,
12 pub fifo: bool,
13 pub environment: Environment,
14}
15
16impl Default for Worker {
17 fn default() -> Self {
18 Worker {
19 name: None,
20 queue_alias: None,
21 concurrency: 1,
22 fifo: false,
23 environment: Environment::new(),
24 }
25 }
26}
27
28impl Parse for Worker {
29 fn parse(input: ParseStream) -> syn::Result<Self> {
30 let mut worker = Worker::default();
31
32 while !input.is_empty() {
33 let ident: Ident = input.parse()?;
34 input.parse::<token::Eq>()?;
35
36 match ident.to_string().as_str() {
37 "name" => {
38 worker.name = Some(input.parse::<LitStr>()?.value());
39 }
40 "queue_alias" => {
41 worker.queue_alias = Some(input.parse::<LitStr>()?.value());
42 }
43 "environment" => {
44 worker.environment = parse_environment(input)?;
45 }
46 "concurrency" => {
47 worker.concurrency = input.parse::<LitInt>()?.base10_parse::<i16>()?;
48 }
49 "fifo" => {
50 worker.fifo = match input.parse::<LitBool>() {
51 Ok(bool) => bool.value,
52 Err(_) => {
53 return Err(input.error("expected boolean value for 'fifo'"));
54 }
55 };
56 }
57 _ => {}
59 }
60
61 if !input.is_empty() {
62 input.parse::<token::Comma>()?;
63 }
64 }
65
66 Ok(worker)
67 }
68}