Struct Client

Source
pub struct Client {
    pub namespace: String,
    pub token: String,
    pub host: String,
    pub port: u32,
    pub retry: u32,
    pub backoff: u32,
    pub http_client: Client,
}
Expand description

The client for lmstfy

Fields§

§namespace: String

The namespace for the client

§token: String

The access token of api

§host: String

The target host for the server

§port: u32

The target port for the server

§retry: u32

Retry when publish failed

§backoff: u32

Backoff milliseconds when retrying

§http_client: Client

http client which is used to communicate with server

Implementations§

Source§

impl Client

The client implementation

Source

pub fn new( namespace: &str, token: &str, host: &str, port: u32, retry: u32, backoff: u32, ) -> Self

Returns a client with the given parameters

§Arguments
  • namespace - A str that holds the namespace of the client
  • token - A str that holds the token for api request
  • host - A str that holds the target server
  • port - A u32 value that holds the target port
  • retry - A u32 value that holds the retry count
  • backoff - A u32 value that holds the backoff value
Source§

impl Client

The API implementation for lmstfy

Source

pub fn config_retry(&mut self, retry: u32, backoff: u32) -> Result<(), APIError>

Set parameters for retrying

§Arguments
  • retry - A u32 value that holds the retry count
  • backoff - A u32 value that holds the dalay milliseconds between retries
Source

pub async fn publish( &self, queue: String, ack_job_id: String, data: Vec<u8>, ttl: u32, tries: u32, delay: u32, ) -> Result<(String, String), APIError>

Publish task to the server

§Arguments
  • queue - A string that holds the queue for the task
  • ack_job_id - A string that holds the job id about to acknowledged
  • data - A vector of byte that holds the content of task
  • ttl - A u32 value that holds the time-to-live value
  • tries - A u32 value that holds the maximize retry count
  • delay - A u32 value that holds the delay value in second
Source

pub async fn consume( &self, queue: String, ttr: u32, timeout: u32, ) -> Result<Vec<Job>, APIError>

Consume a job, consuming will decrease the job’s retry count by 1 firstly

§Arguments
  • queue - A string that holds the queue for consuming

  • ttr - A u32 value that holds the time-to-run value in second. If the job is not finished before the ttr expires, the job will be released for consuming again if the (tries-1) > 0

  • timeout - A u32 value that holds the max waiting time for long polling If it’s zero, this method will return immediately with or without a job; if it’s positive, this method would polling for new job until timeout.

Source

pub async fn batch_consume( &self, queue: String, ttr: u32, timeout: u32, count: u32, ) -> Result<Vec<Job>, APIError>

Consume a batch of jobs

§Arguments
  • queue - A string that holds the queue for consuming

  • ttr - A u32 value that holds the time-to-run value in second. If the job is not finished before the ttr expires, the job will be released for consuming again if the (tries-1) > 0

  • timeout - A u32 value that holds the max waiting time for long polling If it’s zero, this method will return immediately with or without a job; if it’s positive, this method would polling for new job until timeout.

  • count - A u32 value that holds the count of wanted jobs

Source

pub async fn consume_from_queues( &self, queues: Vec<String>, ttr: u32, timeout: u32, ) -> Result<Vec<Job>, APIError>

Consume from multiple queues. Note that the order of the queues in the params implies the priority. eg. consume_from_queues(120, 5, vec!(“queue-a”, “queue-b”, “queue-c”)) if all the queues have jobs to be fetched, the job in queue-a will be return.

§Arguments
  • queues - A string vector that holds the queues for consuming

  • ttr - A u32 value that holds the time-to-run value in second. If the job is not finished before the ttr expires, the job will be released for consuming again if the (tries-1) > 0

  • timeout - A u32 value that holds the max waiting time for long polling If it’s zero, this method will return immediately with or without a job; if it’s positive, this method would polling for new job until timeout.

  • count - A u32 value that holds the count of wanted jobs

Source

pub async fn ack(&self, queue: String, job_id: String) -> Result<(), APIError>

Mark a job as finished, so it won’t be retried by others

§Arguments
  • queue - A string that holds the queue for the job
  • job_id - A string that holds the job id
Source

pub async fn queue_size(&self, queue: String) -> Result<u32, APIError>

Get the queue size. How many pending jobs are ready for consuming.

§Arguments
  • queue - A string that holds the queue name
Source

pub async fn peek_queue(&self, queue: String) -> Result<Option<Job>, APIError>

Peek job from queue without consuming

§Arguments
  • queue - A string that holds the queue name
Source

pub async fn peek_job( &self, queue: String, job_id: String, ) -> Result<Option<Job>, APIError>

Peek a specified job

§Arguments
  • queue - A string that holds the queue name
  • job_id - A string that holds the job id
Source

pub async fn peek_dead_letter( &self, queue: String, ) -> Result<(u32, String), APIError>

Peek the deadletter of the queue

§Arguments
  • queue - A string that holds the queue name
Source

pub async fn respawn_dead_letter( &self, queue: String, limit: i64, ttl: i64, ) -> Result<u32, APIError>

Respawn dead letter

§Arguments
  • queue - A string that holds the queue name
  • limit - A i64 value that holds the limit
  • ttl - A i64 value that holds the time-to-live value in second

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,