Skip to content

Commit

Permalink
add more documentation about "channel_cap" (#19)
Browse files Browse the repository at this point in the history
* add more documentation about "channel_cap"

* cache cargo-rdme

* failure

* use git release instead of cargo search

* change name of step
  • Loading branch information
epwalsh committed Mar 14, 2022
1 parent cdc54a3 commit c86329d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
paths:
- 'src/lib.rs'
- 'README.md'
env:
CACHE_PREFIX: v0

jobs:
readme:
name: README
Expand All @@ -26,11 +29,31 @@ jobs:
profile: minimal
override: true

- name: Find latest cargo-rdme version
shell: bash
run: |
set -e
set -u
set -o pipefail
CARGO_RDME_VERSION=$(curl -s https://api.github.com/repos/orium/cargo-rdme/releases/latest | jq -r '.tag_name')
# Alternate method using cargo (takes longer):
# CARGO_RDME_VERSION=$(cargo search --limit 1 cargo-rdme | grep cargo-rdme | head -n 1 | sed -E 's/cargo-rdme = "([^"]+)".*/v\1/g')
echo "CARGO_RDME_VERSION=$CARGO_RDME_VERSION" >> $GITHUB_ENV
echo "$CARGO_RDME_VERSION"
- name: Cache cargo-rdme
uses: actions/cache@v2
id: cache-cargo-rdme
with:
path: ~/.cargo/bin/cargo-rdme
key: ${{ env.CACHE_PREFIX }}-${{ env.CARGO_RDME_VERSION }}

- name: Install cargo-rdme
if: steps.cache-cargo-rdme.outputs.cache-hit != 'true'
run: |
cargo install cargo-rdme
- name: Run cargo-rdme
- name: Check README is up-to-date
run: |
# If this step fails it means you haven't ran 'make readme' to update the README.
cargo rdme --check
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- Added more documentation about `channel_cap`.

## [v0.2.3](https://github.com/epwalsh/batched-fn/releases/tag/v0.2.3) - 2022-03-11

### Changed
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ macro into the function that runs requests through the model.
- 馃殌 Easy to use: drop the `batched_fn!` macro into existing code.
- 馃敟 Lightweight and fast: queue system implemented on top of the blazingly fast [flume crate](https://github.com/zesterer/flume).
- 馃檶 Easy to tune: simply adjust [`max_delay`](https://docs.rs/batched-fn/latest/batched_fn/macro.batched_fn.html#config) and [`max_batch_size`](https://docs.rs/batched-fn/latest/batched_fn/macro.batched_fn.html#config).
- 馃洃 [Back pressure](https://medium.com/@jayphelps/backpressure-explained-the-flow-of-data-through-software-2350b3e77ce7) mechanism included: just set [`channel_cap`](https://docs.rs/batched-fn/latest/batched_fn/macro.batched_fn.html#config).
- 馃洃 [Back pressure](https://medium.com/@jayphelps/backpressure-explained-the-flow-of-data-through-software-2350b3e77ce7) mechanism included:
just set [`channel_cap`](https://docs.rs/batched-fn/latest/batched_fn/macro.batched_fn.html#config) and handle
[`Error::Full`](https://docs.rs/batched-fn/latest/batched_fn/enum.Error.html#variant.Full) by returning a 503 from your webserver.

## Examples

Expand Down
12 changes: 9 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
//! - 馃殌 Easy to use: drop the `batched_fn!` macro into existing code.
//! - 馃敟 Lightweight and fast: queue system implemented on top of the blazingly fast [flume crate](https://github.com/zesterer/flume).
//! - 馃檶 Easy to tune: simply adjust [`max_delay`](crate::batched_fn#config) and [`max_batch_size`](crate::batched_fn#config).
//! - 馃洃 [Back pressure](https://medium.com/@jayphelps/backpressure-explained-the-flow-of-data-through-software-2350b3e77ce7) mechanism included: just set [`channel_cap`](crate::batched_fn#config).
//! - 馃洃 [Back pressure](https://medium.com/@jayphelps/backpressure-explained-the-flow-of-data-through-software-2350b3e77ce7) mechanism included:
//! just set [`channel_cap`](crate::batched_fn#config) and handle
//! [`Error::Full`](crate::Error#variant.Full) by returning a 503 from your webserver.
//!
//! ## Examples
//!
Expand Down Expand Up @@ -206,6 +208,10 @@ impl Default for Config {
#[derive(Debug, Copy, Clone)]
pub enum Error {
/// Channel is full.
///
/// This can happen if you've set `channel_cap`, and should usually be handled
/// by returning a 503 error code from your server to signal that the server is too
/// busy at the moment to handle any more requests.
Full,

/// Channel has been disconnected, most likely due to the handler thread crashing.
Expand Down Expand Up @@ -383,8 +389,8 @@ macro_rules! __batched_fn_internal {
/// the handler thread to accept another batch. By default `channel_cap` is `None`, but if
/// set to `Some(usize)` then
/// [`BatchedFn::evaluate_in_batch`](struct.BatchedFn.html#method.evaluate_in_batch) will
/// return an error if the channel between the calling thread and the handler thread is at this
/// capacity.
/// return [`Error::Full`](crate::Error#variant.Full) if the channel between the calling thread and the handler thread is at this
/// capacity. You probably want to set this to some multiple of `max_batch_size`.
///
/// ## `context`
///
Expand Down

0 comments on commit c86329d

Please sign in to comment.