parent
d7ea1ffb85
commit
81cefee5bf
22 changed files with 307 additions and 341 deletions
@ -1,3 +1,3 @@ |
||||
FROM centos:7 |
||||
FROM alpine:3.17 |
||||
|
||||
RUN yum update -y |
||||
RUN apk add bash |
@ -1,3 +1,3 @@ |
||||
FROM alpine:latest |
||||
FROM alpine:3.17 |
||||
|
||||
RUN apk add iproute2 bash |
@ -0,0 +1,22 @@ |
||||
use std::{fmt::Debug, time::Duration}; |
||||
use tokio::time::sleep; |
||||
|
||||
pub async fn retry_with_interval<T, E: Debug>( |
||||
retries: usize, |
||||
interval: Duration, |
||||
f: impl Fn() -> Result<T, E>, |
||||
) -> T { |
||||
let mut err = String::new(); |
||||
for i in 0..retries { |
||||
eprintln!("retrier: {} attempt...", i + 1); |
||||
let result = f(); |
||||
match result { |
||||
Ok(r) => return r, |
||||
Err(e) => { |
||||
err = format!("{e:?}"); |
||||
sleep(interval).await; |
||||
} |
||||
} |
||||
} |
||||
panic!("{err}"); |
||||
} |
@ -1,56 +0,0 @@ |
||||
use crate::config::get_self_uid; |
||||
use serde::{Deserialize, Serialize}; |
||||
use std::{borrow::Cow, fmt::Debug}; |
||||
use uuid::Uuid; |
||||
|
||||
pub struct Moo<'cow, T: AsMsg + Clone>(pub Cow<'cow, T>); |
||||
|
||||
pub trait AsMsg: Clone + Serialize + Debug { |
||||
fn as_message(&self) -> BaseMessage<'_, Self> { |
||||
BaseMessage::new(self) |
||||
} |
||||
} |
||||
|
||||
impl<'cow, M: AsMsg> From<M> for Moo<'cow, M> { |
||||
#[inline] |
||||
fn from(obj: M) -> Moo<'cow, M> { |
||||
Moo(Cow::Owned(obj)) |
||||
} |
||||
} |
||||
|
||||
impl<'cow, M: AsMsg> From<&'cow M> for Moo<'cow, M> { |
||||
#[inline] |
||||
fn from(obj: &'cow M) -> Moo<'cow, M> { |
||||
Moo(Cow::Borrowed(obj)) |
||||
} |
||||
} |
||||
|
||||
impl<M: AsMsg> AsMsg for Vec<M> {} |
||||
impl<'msg, M: AsMsg> AsMsg for &'msg [M] {} |
||||
|
||||
#[derive(Serialize, Deserialize, Debug)] |
||||
pub struct BaseMessage<'cow, I: AsMsg> { |
||||
pub id: Uuid, |
||||
inner: Cow<'cow, I>, |
||||
} |
||||
|
||||
impl<'cow, I: AsMsg> BaseMessage<'cow, I> { |
||||
pub fn new<C>(inner: C) -> Self |
||||
where |
||||
C: Into<Moo<'cow, I>>, |
||||
{ |
||||
let Moo(inner) = inner.into(); |
||||
Self { |
||||
id: get_self_uid(), |
||||
inner, |
||||
} |
||||
} |
||||
|
||||
pub fn into_inner(self) -> I { |
||||
self.inner.into_owned() |
||||
} |
||||
|
||||
pub fn as_inner(&self) -> &I { |
||||
self.inner.as_ref() |
||||
} |
||||
} |
@ -1,5 +1,5 @@ |
||||
use std::env; |
||||
|
||||
fn main() { |
||||
println!("{}", env::args().nth(1).unwrap_or(String::new())); |
||||
println!("{}", env::args().skip(1).collect::<Vec<String>>().join(" ")); |
||||
} |
||||
|
Loading…
Reference in new issue