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
impl Client
The client implementation
Sourcepub fn new(
namespace: &str,
token: &str,
host: &str,
port: u32,
retry: u32,
backoff: u32,
) -> Self
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 clienttoken
- A str that holds the token for api requesthost
- A str that holds the target serverport
- A u32 value that holds the target portretry
- A u32 value that holds the retry countbackoff
- A u32 value that holds the backoff value
Source§impl Client
The API implementation for lmstfy
impl Client
The API implementation for lmstfy
Sourcepub fn config_retry(&mut self, retry: u32, backoff: u32) -> Result<(), APIError>
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 countbackoff
- A u32 value that holds the dalay milliseconds between retries
Sourcepub async fn publish(
&self,
queue: String,
ack_job_id: String,
data: Vec<u8>,
ttl: u32,
tries: u32,
delay: u32,
) -> Result<(String, String), APIError>
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 taskack_job_id
- A string that holds the job id about to acknowledgeddata
- A vector of byte that holds the content of taskttl
- A u32 value that holds the time-to-live valuetries
- A u32 value that holds the maximize retry countdelay
- A u32 value that holds the delay value in second
Sourcepub async fn consume(
&self,
queue: String,
ttr: u32,
timeout: u32,
) -> Result<Vec<Job>, APIError>
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 thettr
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.
Sourcepub async fn batch_consume(
&self,
queue: String,
ttr: u32,
timeout: u32,
count: u32,
) -> Result<Vec<Job>, APIError>
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 thettr
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
Sourcepub async fn consume_from_queues(
&self,
queues: Vec<String>,
ttr: u32,
timeout: u32,
) -> Result<Vec<Job>, APIError>
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 thettr
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
Sourcepub async fn ack(&self, queue: String, job_id: String) -> Result<(), APIError>
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 jobjob_id
- A string that holds the job id
Sourcepub async fn queue_size(&self, queue: String) -> Result<u32, APIError>
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
Sourcepub async fn peek_job(
&self,
queue: String,
job_id: String,
) -> Result<Option<Job>, APIError>
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