Skip to content

Commit 437c4b3

Browse files
committed
Update docs to be more clear
With new TLS capabilities the client can use some extra clarity in the docs.
1 parent 9c6e243 commit 437c4b3

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

rustygear/src/client.rs

+32-24
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ impl Display for JobStatus {
8181
/// Client for interacting with Gearman service
8282
///
8383
/// Both workers and clients will use this as the top-level object to communicate
84-
/// with a gearman server. [Client.new] should produce a functioning structure which
84+
/// with a gearman server. [Client::new] should produce a functioning structure which
8585
/// should then be configured as needed. It will not do anything useful until after
86-
/// [Client.connect] has been called.
86+
/// [Client::connect] has been called.
8787
///
88-
/// See examples/client.rs and examples/worker.rs for information on how to use it.
88+
/// See examples for more information on how to use it.
8989
pub struct Client {
9090
servers: Vec<Hostname>,
9191
conns: Arc<Mutex<Connections>>,
@@ -111,11 +111,8 @@ impl fmt::Display for ClientJob {
111111
}
112112
}
113113

114-
/// Passed to workers
114+
/// This structure is passed to worker functions after a JOB_ASSIGN_UNIQ packet is received.
115115
///
116-
/// The sink_tx property of this structure can be used to send raw packets
117-
/// to the gearman server from workers, although this is not known to work
118-
/// generically as of this writing.
119116
pub struct WorkerJob {
120117
pub handle: Bytes,
121118
pub function: Bytes,
@@ -164,10 +161,9 @@ impl ClientJob {
164161
&self.handle
165162
}
166163

167-
/// Should only return when the worker has sent data or completed the job. Errors if used on background jobs.
164+
/// Should only return when the worker has sent data or completed the job.
168165
///
169-
/// Use this in clients to wait for a response on a job that was submitted. This will block
170-
/// forever or error if used on a background job.
166+
/// Use this in clients to wait for a response on a job that was submitted. This will return an error if used on a background job.
171167
pub async fn response(&mut self) -> Result<WorkUpdate, io::Error> {
172168
if let Some(workupdate) = self.response_rx.recv().await {
173169
Ok(workupdate)
@@ -194,10 +190,21 @@ impl WorkerJob {
194190
/// Sends a WORK_STATUS
195191
///
196192
/// This will send a WORK_STATUS packet to the server, and can be called from a worker,
197-
/// although that worker may need to manage its own runtime, and as of this writing, this
198-
/// method may not be functional.
193+
/// although that worker may need to manage its own async runtime to execute this function.
199194
///
200-
/// See examples/worker.rs for an idea of how it may work.
195+
/// ```
196+
/// fn sends_status(work: &mut WorkerJob) -> Result<Vec<u8>, std::io::Error> {
197+
/// let rt = tokio::runtime::Builder::new_current_thread()
198+
/// .build()
199+
/// .unwrap();
200+
/// rt.block_on(work.work_status(50, 100))?;
201+
/// Ok("Done".into())
202+
/// }
203+
/// let mut worker = worker
204+
/// .can_do("statusfunc", sends_status)
205+
/// .await
206+
/// .expect("CAN_DO should succeed");
207+
/// ```
201208
pub async fn work_status(&mut self, numerator: u32, denominator: u32) -> Result<(), io::Error> {
202209
let numerator = format!("{}", numerator);
203210
let denominator = format!("{}", denominator);
@@ -222,7 +229,7 @@ impl WorkerJob {
222229

223230
/// Sends a WORK_FAIL
224231
///
225-
/// This method is typically called by the [Client.work] method upon return
232+
/// This method is typically called by the [Client::work] method upon return
226233
/// of an error from the assigned closure.
227234
pub async fn work_fail(&mut self) -> Result<(), io::Error> {
228235
let packet = new_res(WORK_FAIL, self.handle.clone());
@@ -231,7 +238,7 @@ impl WorkerJob {
231238

232239
/// Sends a WORK_COMPLETE
233240
///
234-
/// This method is typically called by the [Client.work] method upon return of
241+
/// This method is typically called by the [Client::work] method upon return of
235242
/// the assigned closure.
236243
pub async fn work_complete(&mut self, response: Vec<u8>) -> Result<(), io::Error> {
237244
let mut payload = BytesMut::with_capacity(self.handle.len() + 1 + self.payload.len());
@@ -261,8 +268,8 @@ impl Client {
261268
self
262269
}
263270

264-
/// Call this to enable TLS/SSL connections to servers.
265-
/// This takes a rustls::ClientConfig object which allows a lot of flexiblity in how TLS operates.
271+
/// Call this to enable TLS/SSL connections to servers. If it is never called, the connection will remain plain.
272+
/// This takes a [ClientConfig] object which allows a lot of flexibility in how TLS will operate.
266273
pub fn set_tls_config(mut self, config: ClientConfig) -> Self {
267274
self.tls = Some(config);
268275
self
@@ -497,7 +504,7 @@ impl Client {
497504
Ok(self)
498505
}
499506

500-
/// Sends an ECHO_REQ to the server, a good way to confirm the connection is alive
507+
/// Sends an ECHO_REQ to the first server, a good way to confirm the connection is alive
501508
///
502509
/// Returns an error if there aren't any connected servers, or no ECHO_RES comes back
503510
pub async fn echo(&mut self, payload: &[u8]) -> Result<(), io::Error> {
@@ -523,13 +530,14 @@ impl Client {
523530
Ok(())
524531
}
525532

526-
/// Submits a foreground job. The see [ClientJob.response] for how to see the response from the
527-
/// worker.
533+
/// Submits a foreground job. The see [ClientJob::response] for how to see the response from the
534+
/// worker. The unique ID will be generated using [Uuid::new_v4]
528535
pub async fn submit(&mut self, function: &str, payload: &[u8]) -> Result<ClientJob, io::Error> {
529536
self.direct_submit(SUBMIT_JOB, function, payload, None)
530537
.await
531538
}
532539

540+
/// Submits a job with an explicit unique ID.
533541
pub async fn submit_unique(
534542
&mut self,
535543
function: &str,
@@ -541,7 +549,7 @@ impl Client {
541549
}
542550

543551
/// Submits a background job. The [ClientJob] returned won't be able to use the
544-
/// [ClientJob.response] method because the server will never send packets for it.
552+
/// [ClientJob::response] method because the server will never send packets for it.
545553
pub async fn submit_background(
546554
&mut self,
547555
function: &str,
@@ -552,7 +560,7 @@ impl Client {
552560
}
553561

554562
/// Submits a background job. The [ClientJob] returned won't be able to use the
555-
/// [ClientJob.response] method because the server will never send packets for it.
563+
/// [ClientJob::response] method because the server will never send packets for it.
556564
pub async fn submit_background_unique(
557565
&mut self,
558566
function: &str,
@@ -712,7 +720,7 @@ impl Client {
712720
}
713721

714722
/// Receive and do just one job. Will not return until a job is done or there
715-
/// is an error. See [Client.work] for more information.
723+
/// is an error. This is called in a loop by [Client::work].
716724
pub async fn do_one_job(&mut self) -> Result<(), io::Error> {
717725
let job = self.client_data.receivers().worker_job_rx.try_recv();
718726
let job = match job {
@@ -769,7 +777,7 @@ impl Client {
769777
/// Run the assigned jobs through can_do functions until an error happens
770778
///
771779
/// After you have set up all functions your worker can do via the
772-
/// [Client.can_do] method, call this function to begin working. It will
780+
/// [Client::can_do] method, call this function to begin working. It will
773781
/// not return unless there is an unexpected error.
774782
///
775783
/// See examples/worker.rs for more information on how to use it.

0 commit comments

Comments
 (0)