diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fb26754..e345ed2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,21 +39,37 @@ jobs: RUSTDOCFLAGS: -D warnings test: - name: Test (${{ matrix.toolchain }}) + name: Test (${{ matrix.name }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: - # `msrv` resolves to the workspace `rust-version`. - toolchain: [ stable, msrv ] + include: + # The whole workspace on stable. No broker here: the live Redis tests skip (the `redis` job + # runs them with a broker and BQ_REQUIRE_REDIS). + - name: stable + toolchain: stable + manifest: Cargo.toml + command: cargo test --workspace --all-features --locked + # Each crate on its own floor: `msrv` resolves to the `rust-version` of the manifest. The + # core stays at the workspace floor; `babelqueue-redis` sets a higher one (the `redis` + # crate's), so its leg builds it, tests included, without running them against a broker. + - name: msrv core + toolchain: msrv + manifest: Cargo.toml + command: cargo test -p babelqueue --locked + - name: msrv redis + toolchain: msrv + manifest: crates/babelqueue-redis/Cargo.toml + command: cargo test -p babelqueue-redis --all-features --locked --no-run steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 - name: Resolve toolchain id: tc run: | if [ "${{ matrix.toolchain }}" = "msrv" ]; then - v="$(sed -n 's/^rust-version *= *"\(.*\)"/\1/p' Cargo.toml | head -n1)" - [ -n "$v" ] || { echo "rust-version not found in Cargo.toml" >&2; exit 1; } + v="$(sed -n 's/^rust-version *= *"\(.*\)"/\1/p' "${{ matrix.manifest }}" | head -n1)" + [ -n "$v" ] || { echo "rust-version not found in ${{ matrix.manifest }}" >&2; exit 1; } else v="${{ matrix.toolchain }}" fi @@ -62,8 +78,53 @@ jobs: run: rustup toolchain install "${{ steps.tc.outputs.version }}" --profile minimal && rustup default "${{ steps.tc.outputs.version }}" - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 with: - key: ${{ matrix.toolchain }} - - run: cargo test --workspace --all-features --locked + key: ${{ matrix.name }} + - run: ${{ matrix.command }} + + redis: + name: Redis (live broker) and results.json + runs-on: ubuntu-latest + # The redis conformance sections and the live tests need a real broker: BQ_REQUIRE_REDIS makes a + # missing one fail instead of letting the cases skip (broker-bindings section 1, runner contract). + services: + redis: + image: redis:7 + ports: + - 6379:6379 + options: >- + --health-cmd "redis-cli ping" + --health-interval 5s --health-timeout 3s --health-retries 5 + env: + REDIS_URL: redis://localhost:6379/0 + BQ_REQUIRE_REDIS: "1" + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + - name: Install stable toolchain + run: rustup toolchain install stable --profile minimal && rustup default stable + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 + # Every crate with a conformance runner writes the sections it ran to a file of its own + # (BQ_CONFORMANCE_RESULTS); merge-conformance-results.py joins them and derives `bindings` + # from the crates in the tree. + - name: Core conformance (partial results) + run: cargo test -p babelqueue --all-features --locked --test conformance + env: + BQ_CONFORMANCE_RESULTS: ${{ runner.temp }}/results/core.json + - name: Redis tests, live and conformance (partial results) + run: cargo test -p babelqueue-redis --all-features --locked + env: + BQ_CONFORMANCE_RESULTS: ${{ runner.temp }}/results/redis.json + - name: Merge results.json (ADR-0032) + run: | + python3 scripts/merge-conformance-results.py "$RUNNER_TEMP/results.json" \ + "$RUNNER_TEMP/results/core.json" "$RUNNER_TEMP/results/redis.json" + # Schema-valid, no `fail`, bindings derived from the crates in the tree, and every in-scope + # section and case present: a transport crate without its sections breaks CI. + - name: Validate results.json + run: | + python3 -m venv "$RUNNER_TEMP/venv" + "$RUNNER_TEMP/venv/bin/pip" install --quiet jsonschema==4.23.0 + "$RUNNER_TEMP/venv/bin/python" -I scripts/check-conformance-results.py \ + "$RUNNER_TEMP/results.json" testdata/conformance "$BQ_CONFORMANCE_VERSION" conformance: name: Conformance suite in sync @@ -91,7 +152,7 @@ jobs: ci-green: name: CI green runs-on: ubuntu-latest - needs: [lint, test, conformance, deny] + needs: [lint, test, redis, conformance, deny] if: ${{ always() }} steps: - name: Fail if any required job did not pass diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..da64cd3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,246 @@ +name: Release + +# A `v*` tag publishes `babelqueue` (the core); a `redis/v*` tag publishes `babelqueue-redis` (the +# same prefix scheme as babelqueue-go). `babelqueue-redis` depends on the core by version, so the +# core must be on crates.io first: the publish job of a `redis/v*` run waits (up to 15 minutes) for +# that core version before publishing, so pushing both tags together is safe, and pushing the core +# tag first is still the clean order. +# +# The first release of each crate is made by hand with a token (crates.io trusted publishing can +# only be configured for a crate that exists). The publish step below asks crates.io whether the tag's +# version is already there and, if so, skips `cargo publish` and still creates the GitHub release +# with the results.json asset, so the order "manual `cargo publish` -> trusted publisher +# registration -> tag push" works without a failed run. +# +# A manual run (workflow_dispatch) is a dry run: tests, conformance, results.json and +# `cargo publish --dry-run` run, nothing is published or released. +on: + push: + tags: + - "v*" # babelqueue (core) + - "redis/v*" # babelqueue-redis + workflow_dispatch: + +concurrency: + group: release-${{ github.ref }} + cancel-in-progress: false + +permissions: + contents: read + +env: + CARGO_TERM_COLOR: always + CARGO_INCREMENTAL: "0" + # The conformance suite release this repo is vendored from and must report against. + BQ_CONFORMANCE_VERSION: "1.11.0" + # sha256 of that release's fetch.sh: the script runs on the runner, so it is pinned rather than + # trusted from a mutable tag. Bump together with BQ_CONFORMANCE_VERSION (and ci.yml). + BQ_FETCH_SH_SHA256: 8bb6ba567b288fb0ac71a70fd17041b2503df119e01998d76fdad372570bf849 + +# Third-party actions are pinned to a commit SHA (supply chain, ADR-0041 D7). +# actions/checkout v7.0.1 +# Swatinem/rust-cache v2.9.3 +# actions/upload-artifact v4.6.2 +# actions/download-artifact v4.3.0 +# rust-lang/crates-io-auth-action v1.0.6 +# softprops/action-gh-release v3.0.5 +jobs: + verify: + name: Verify (tests, conformance, publish dry run) + runs-on: ubuntu-latest + permissions: + contents: read + outputs: + crate: ${{ steps.target.outputs.crate }} + version: ${{ steps.target.outputs.version }} + # A Redis broker for the published results.json: the redis conformance sections and the live + # tests must run (BQ_REQUIRE_REDIS makes a missing broker fail), as in ci.yml. + services: + redis: + image: redis:7 + ports: + - 6379:6379 + options: >- + --health-cmd "redis-cli ping" + --health-interval 5s --health-timeout 3s --health-retries 5 + env: + REDIS_URL: redis://localhost:6379/0 + BQ_REQUIRE_REDIS: "1" + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + - name: Install stable toolchain + run: rustup toolchain install stable --profile minimal && rustup default stable + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 + + # The tag decides the crate; the manifest decides the version, and they must agree. A tag + # that matches no crate, or a version the manifest does not carry, stops the release here. + - name: Resolve crate and version from the tag + id: target + if: ${{ github.event_name == 'push' }} + env: + REF_NAME: ${{ github.ref_name }} + run: | + set -euo pipefail + case "$REF_NAME" in + redis/v*) crate=babelqueue-redis; version="${REF_NAME#redis/v}" ;; + v*) crate=babelqueue; version="${REF_NAME#v}" ;; + *) echo "release: tag '$REF_NAME' maps to no crate" >&2; exit 1 ;; + esac + if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then + echo "release: '$version' is not a semantic version" >&2; exit 1 + fi + manifest="$(cargo metadata --no-deps --format-version 1 --locked \ + | jq -r --arg c "$crate" '.packages[] | select(.name == $c) | .version')" + if [ "$manifest" != "$version" ]; then + echo "release: tag version '$version' != $crate manifest version '$manifest'" >&2; exit 1 + fi + # A dated heading: `## [0.1.0] - Unreleased` is a draft and must not be tagged. + if ! grep -Eq "^## \[${version//./\\.}\] - [0-9]{4}-[0-9]{2}-[0-9]{2}" CHANGELOG.md; then + echo "release: CHANGELOG.md has no dated '## [$version] - YYYY-MM-DD' section" >&2; exit 1 + fi + echo "crate=$crate" >> "$GITHUB_OUTPUT" + echo "version=$version" >> "$GITHUB_OUTPUT" + + # The vendored suite must be byte-identical to the pinned conformance release, or the + # results.json would attest a suite nobody can reproduce. + - name: Verify vendored conformance matches the pinned release + run: | + curl -fsSL -o "$RUNNER_TEMP/fetch.sh" \ + "https://raw.githubusercontent.com/BabelQueue/conformance/v${BQ_CONFORMANCE_VERSION}/fetch.sh" + echo "${BQ_FETCH_SH_SHA256} $RUNNER_TEMP/fetch.sh" | sha256sum -c - + bash "$RUNNER_TEMP/fetch.sh" --check "$BQ_CONFORMANCE_VERSION" testdata/conformance + + - name: Test the workspace + run: cargo test --workspace --all-features --locked + + # Each crate with a conformance runner writes the sections it ran to a file of its own; + # merge-conformance-results.py joins them and derives `bindings` from the crates in the tree. + - name: Core conformance (partial results) + run: cargo test -p babelqueue --all-features --locked --test conformance + env: + BQ_CONFORMANCE_RESULTS: ${{ runner.temp }}/results/core.json + - name: Redis conformance (partial results) + run: cargo test -p babelqueue-redis --all-features --locked --test conformance + env: + BQ_CONFORMANCE_RESULTS: ${{ runner.temp }}/results/redis.json + - name: Merge results.json (ADR-0032) + run: | + python3 scripts/merge-conformance-results.py "$RUNNER_TEMP/results.json" \ + "$RUNNER_TEMP/results/core.json" "$RUNNER_TEMP/results/redis.json" + # Schema-valid, no `fail`, bindings derived from the crates in the tree, and every in-scope + # section and case present: a crate without its sections breaks the release. + - name: Validate results.json + run: | + python3 -m venv "$RUNNER_TEMP/venv" + "$RUNNER_TEMP/venv/bin/pip" install --quiet jsonschema==4.23.0 + "$RUNNER_TEMP/venv/bin/python" -I scripts/check-conformance-results.py \ + "$RUNNER_TEMP/results.json" testdata/conformance "$BQ_CONFORMANCE_VERSION" + mkdir -p "$RUNNER_TEMP/release-assets" + cp "$RUNNER_TEMP/results.json" "$RUNNER_TEMP/release-assets/results.json" + + # Both crates in one call: `babelqueue-redis` depends on the core by version, and the core is + # not on crates.io yet before its first release, so cargo verifies them together (the core is + # taken from the same run). A single `-p babelqueue-redis` dry run cannot resolve it then. + - name: Publish dry run (both crates) + run: cargo publish --dry-run -p babelqueue -p babelqueue-redis --locked + + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 + with: + name: release-assets + path: ${{ runner.temp }}/release-assets/results.json + if-no-files-found: error + + publish: + name: Publish to crates.io and create the GitHub release + needs: verify + if: ${{ github.event_name == 'push' }} + runs-on: ubuntu-latest + # The environment name and this workflow file are what the crates.io trusted publisher is + # registered against; id-token is requested only here, never in the verify job. + environment: crates-io + permissions: + contents: write + id-token: write + env: + CRATE: ${{ needs.verify.outputs.crate }} + VERSION: ${{ needs.verify.outputs.version }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + - name: Install stable toolchain + run: rustup toolchain install stable --profile minimal && rustup default stable + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 + with: + name: release-assets + path: release-assets + + # The first-release mechanism: ask crates.io about exactly this crate and version. 200 means + # it was published by hand (or by an earlier run): skip the publish. 404 means publish. Any + # other answer is not a decision, so the run fails rather than guessing. A yanked version + # still answers 200: it cannot be published again. + - name: Is this version already on crates.io? + id: published + run: | + set -euo pipefail + code="$(curl -sS -o /dev/null -w '%{http_code}' \ + -A "babelqueue-rust-release (https://github.com/BabelQueue/babelqueue-rust)" \ + "https://crates.io/api/v1/crates/${CRATE}/${VERSION}")" + case "$code" in + 200) echo "exists=true" >> "$GITHUB_OUTPUT"; echo "$CRATE $VERSION is already on crates.io: skipping cargo publish" ;; + 404) echo "exists=false" >> "$GITHUB_OUTPUT" ;; + *) echo "crates.io answered HTTP $code for $CRATE $VERSION" >&2; exit 1 ;; + esac + + # `babelqueue-redis` resolves `babelqueue` from crates.io at publish time, by the version + # requirement in its own manifest (not by the workspace version). Wait for the lowest version + # that requirement names: when both tags are pushed at once the core run may still be + # publishing. A redis-only release whose requirement an already-published core satisfies (say + # `0.1.0` while the workspace is 0.1.1) therefore needs no new core release. Bounded. + - name: Wait for the core version on crates.io (redis tag only) + if: ${{ steps.published.outputs.exists == 'false' && env.CRATE == 'babelqueue-redis' }} + run: | + set -euo pipefail + # cargo metadata normalizes `version = "0.1.0"` to the requirement "^0.1.0"; strip the + # operator and keep the version it names (^, ~, = and >= all name their lowest version). + req="$(cargo metadata --no-deps --format-version 1 --locked \ + | jq -r '.packages[] | select(.name == "babelqueue-redis") | .dependencies[] | select(.name == "babelqueue") | .req')" + core="$(printf '%s' "$req" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?' | head -n1 || true)" + [ -n "$core" ] || { echo "release: no babelqueue version found in the requirement '$req' of babelqueue-redis" >&2; exit 1; } + echo "babelqueue-redis requires babelqueue $req; waiting for $core" + for attempt in $(seq 1 45); do + code="$(curl -sS -o /dev/null -w '%{http_code}' \ + -A "babelqueue-rust-release (https://github.com/BabelQueue/babelqueue-rust)" \ + "https://crates.io/api/v1/crates/babelqueue/${core}")" + if [ "$code" = "200" ]; then + echo "babelqueue $core is on crates.io" + sleep 15 # let the sparse index catch up with the API before cargo resolves it + exit 0 + fi + echo "babelqueue $core not on crates.io yet (HTTP $code), attempt $attempt/45" + sleep 20 + done + echo "release: babelqueue $core did not appear on crates.io within 15 minutes; publish the core first" >&2 + exit 1 + + - name: Authenticate to crates.io (trusted publishing) + id: auth + if: ${{ steps.published.outputs.exists == 'false' }} + uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 + + - name: cargo publish + if: ${{ steps.published.outputs.exists == 'false' }} + run: cargo publish -p "$CRATE" --locked + env: + CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} + + - name: Create GitHub Release + uses: softprops/action-gh-release@88b783939ccdbabad21b9a37510aed7fad5f2e60 + with: + tag_name: ${{ github.ref_name }} + generate_release_notes: true + # A version with a pre-release suffix (0.2.0-rc.1) must not become "Latest". + prerelease: ${{ contains(needs.verify.outputs.version, '-') }} + files: release-assets/results.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 8716687..dab0874 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,47 @@ The envelope wire format is versioned separately by `meta.schema_version` ## [Unreleased] +## [0.1.0] - Unreleased + +First release: the `babelqueue` core and the `babelqueue-redis` transport. The wire envelope is +`schema_version: 1`; the conformance suite is pinned to 1.11.0 (`results.json` is attached to the +GitHub release). The date is set when the tag is pushed. + ### Added -- Cargo workspace skeleton: `babelqueue` (core) and `babelqueue-redis` crates (ADR-0041). -- CI: fmt, clippy, docs, tests on stable and the MSRV toolchain, `cargo deny`, and a vendored - conformance suite check pinned to conformance 1.11.0. +#### `babelqueue` (core) + +- Envelope codec: `make`, `decode`, `Envelope::encode`. `data` and unknown keys are kept as raw + text and re-emitted byte for byte (only `attempts` changes); strict `data` serializer that rejects + forbidden keys and non-finite numbers; the inbound `urn` alias; failures are values + (`DecodeError`, `EncodeError`). +- Runtime: `App` publishes and consumes by URN over an async `Transport` (native `async fn` in + traits, no executor), with the unknown-URN strategies, the `schema_version` gate, poison routing, + retry with backoff and jitter, the dead-letter `dead_letter` block (same shape as the Go and + Python SDKs) and containment of handler panics. Optional transport capabilities are separate + traits (`HeaderPublisher`, `Releaser`, `DeadLetterSettler`). +- `InMemoryTransport` for tests and broker-free runs; idempotency wrapper (ADR-0022); payload + schema subset (ADR-0024); conformance `results.json` writer (ADR-0032). +- Only `serde`, `serde_json` and `getrandom` are linked; `unsafe` code is forbidden. + +#### `babelqueue-redis` + +- Redis transport (broker-bindings section 1) with both layouts: Laravel-compatible zset + (`queues:`, `:delayed`, `:reserved`, `:notify`; the default) and the legacy reliable queue. +- Laravel's pop script, delayed publishing, in-place release, `retry_after` recovery, a blocking + connection pool, invalid UTF-8 bodies routed to poison. Optional `tls-rustls` feature. + +#### Project + +- CI: fmt, clippy, docs, tests on stable and each crate's MSRV, `cargo deny`, vendored conformance + check (`fetch.sh --check`), live Redis tests with `BQ_REQUIRE_REDIS`. +- Release workflow: a `v*` tag publishes `babelqueue`, a `redis/v*` tag publishes + `babelqueue-redis`, through crates.io trusted publishing. + +### Notes + +- MSRV: `babelqueue` 1.85, `babelqueue-redis` 1.88 (set by the `redis` crate). Raising an MSRV is a + MINOR release. + +[Unreleased]: https://github.com/BabelQueue/babelqueue-rust/compare/v0.1.0...HEAD +[0.1.0]: https://github.com/BabelQueue/babelqueue-rust/releases/tag/v0.1.0 diff --git a/Cargo.lock b/Cargo.lock index 91e6d12..0d7cf39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,11 +2,65 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "aho-corasick" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba" +dependencies = [ + "memchr", +] + +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + +[[package]] +name = "anstyle" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c7a9e344b352bef7873e51ff425c2f90d5aa2a252db2b84289c93ff30beb3d7" + +[[package]] +name = "arc-swap" +version = "1.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84a22b5d51209f6de83d37a0b33d320acb8da88823e42a94c075140708f032a5" +dependencies = [ + "rustversion", +] + +[[package]] +name = "arcstr" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03918c3dbd7701a85c6b9887732e2921175f26c350b4563841d0958c21d57e6d" + +[[package]] +name = "async-lock" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0876700b0d007ad25d5508865a4259c3af9af6d296bf663a0d586d0bc3369f6f" +dependencies = [ + "event-listener", + "event-listener-strategy", + "pin-project-lite", +] + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + [[package]] name = "babelqueue" version = "0.1.0" dependencies = [ - "getrandom", + "criterion", + "getrandom 0.3.4", "serde", "serde_json", ] @@ -16,6 +70,48 @@ name = "babelqueue-redis" version = "0.1.0" dependencies = [ "babelqueue", + "getrandom 0.3.4", + "redis", + "serde_json", + "tokio", + "tracing", +] + +[[package]] +name = "backon" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa51bf3329e243b4ceebb25fddaa797b3e2d225c733b215548ffd1fa99294d5d" +dependencies = [ + "fastrand", +] + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" + +[[package]] +name = "bytes" +version = "1.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "776dfebd015e2d8732c684a2c71003674ccb49457b539b9e82151ba38e96dd7c" + +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + +[[package]] +name = "cc" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53b4e5299ae8fd0d9e848f3efafd5b4feed729b8c731df9d62375cb1efdc3f4e" +dependencies = [ + "find-msvc-tools", + "shlex", ] [[package]] @@ -25,58 +121,650 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" [[package]] -name = "getrandom" -version = "0.3.4" +name = "ciborium" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" + +[[package]] +name = "ciborium-ll" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" +dependencies = [ + "ciborium-io", + "half", +] + +[[package]] +name = "clap" +version = "4.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50066ca966813ca8957ee15361752f19424a8ff620dbe9c8993d9f99d99b04b3" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0ed97c96ef4efb3cc84e09fa388df4463e7cc3224ec38d7b1d9e45749333590" +dependencies = [ + "anstyle", + "clap_lex", +] + +[[package]] +name = "clap_lex" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0921b3876b3a1df8a1c9f912e7f94342458022c2e84288015893d83c4d62a79" + +[[package]] +name = "combine" +version = "4.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4356eba6976435498d05a311ee9fc486da3bc81c200d3f0d7dd9703b41913f92" +dependencies = [ + "bytes", + "futures-core", + "memchr", + "pin-project-lite", + "tokio", + "tokio-util", +] + +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "criterion" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1c047a62b0cc3e145fa84415a3191f628e980b194c2755aa12300a4e6cbd928" +dependencies = [ + "anes", + "cast", + "ciborium", + "clap", + "criterion-plot", + "itertools", + "num-traits", + "oorandom", + "regex", + "serde", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b1bcc0dc7dfae599d84ad0b1a55f80cde8af3725da8313b528da95ef783e338" +dependencies = [ + "cast", + "itertools", +] + +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "either" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be" + +[[package]] +name = "event-listener" +version = "5.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a23add41df1562121a9393cb065eab5146a1242410f23a644851e90cfd669d2" +dependencies = [ + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" +dependencies = [ + "event-listener", + "pin-project-lite", +] + +[[package]] +name = "fastrand" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" + +[[package]] +name = "find-msvc-tools" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f35b0b9b788e7109a8eb0607f5c8a13495edee3ef8e246f60f0664a7cd25b277" + +[[package]] +name = "form_urlencoded" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afa489199eaffb1211795df1c6236ce1ad0d41a6fa45250add73e3b02420f06e" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-sink", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasip2", +] + +[[package]] +name = "half" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b" +dependencies = [ + "cfg-if", + "crunchy", + "zerocopy", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" + +[[package]] +name = "libc" +version = "0.2.191" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" + +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "mio" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20521a903f02b0a573cd6840e9d0a5a0cc043d361fe924092cd70f8556cc9c4a" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "oorandom" +version = "11.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" + +[[package]] +name = "openssl-probe" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e036b411754132fd6b74e94b74e9a13c5cf606fa93d1885c35860d3060820b1" + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f120c8d5021b34abd2f2ffd7ee96687cbcd6c54a3e68d86b6169f4a5cd480ffe" + +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "redis" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85db9332bbc47e826283f0a6058d747c478ed2278976279cefd22154d541b98" +dependencies = [ + "arc-swap", + "arcstr", + "async-lock", + "backon", + "bytes", + "cfg-if", + "combine", + "futures-channel", + "futures-util", + "itoa", + "percent-encoding", + "pin-project-lite", + "rustls", + "rustls-native-certs", + "ryu", + "sha1_smol", + "socket2", + "tokio", + "tokio-rustls", + "tokio-util", + "url", + "xxhash-rust", +] + +[[package]] +name = "regex" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9807af0e638c12e753aa1b4e601791bf2a8f71274023c8bbeec12fc149950857" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d60ef07df457506a0a1a2073112eb4aae5733dbd2813c3da77d1b0fd441158" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6" + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86c8de8f13bac4bb046743409c751e2343621c0293a805c143ede57c5c95c3f8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-native-certs" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a073f5dc7469f984c52ad2752b63b0807745133b6de880b7b64c1ac4c48aec4" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pki-types" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "102f35f7de7b06d8c61f1cff6592f5253e0dea431c74867aad5dfd70f44663fb" +dependencies = [ + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +checksum = "e3a0760a887c14823fca5a1c970b01d47c328c696c0c64829d1df50e8f853fd5" dependencies = [ - "cfg-if", - "libc", - "r-efi", - "wasip2", + "ring", + "rustls-pki-types", + "untrusted", ] [[package]] -name = "itoa" -version = "1.0.19" +name = "rustversion" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" [[package]] -name = "libc" -version = "0.2.191" +name = "ryu" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" [[package]] -name = "memchr" -version = "2.8.3" +name = "same-file" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] [[package]] -name = "proc-macro2" -version = "1.0.107" +name = "schannel" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +checksum = "9cb23c424d8ee841bb4d813677ca237e2a610067d594fec130f87d6093495ab5" dependencies = [ - "unicode-ident", + "windows-sys 0.61.2", ] [[package]] -name = "quote" -version = "1.0.47" +name = "security-framework" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" dependencies = [ - "proc-macro2", + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", ] [[package]] -name = "r-efi" -version = "5.3.0" +name = "security-framework-sys" +version = "2.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" +dependencies = [ + "core-foundation-sys", + "libc", +] [[package]] name = "serde" @@ -85,6 +773,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" dependencies = [ "serde_core", + "serde_derive", ] [[package]] @@ -104,7 +793,7 @@ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 3.0.10", ] [[package]] @@ -120,6 +809,63 @@ dependencies = [ "zmij", ] +[[package]] +name = "sha1_smol" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbfa15b3dddfee50a0fff136974b3e1bde555604ba463834a7eb7deb6417705d" + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.16.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3244542535d5de959d90ec55d1b5ff0fd2bb7b1310223907d5f11932847f7b59" + +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "3.0.10" @@ -131,12 +877,160 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "tinystr" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abc840c238154d58f9e86b2792261edfde565a17696e1cda1a449de27979801a" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "tokio" +version = "1.54.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3" +dependencies = [ + "libc", + "mio", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9cc2678c2cdd569ef8215e2afd7954ada2ae20b4fdd2c5fe6139a3b02d105db" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e464cf451ba96ebfc6f9b6542f17ee8b8956e33f1e40d9690624e59d7a7f8a4b" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "libc", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + [[package]] name = "unicode-ident" version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f00cd2407bb42c0ef17be88d4cf020f5cceffd121665bac9b8b9493a369b3b1a" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af3bd9d3e571c26fcce9d033b87ea5ab061b8d2ffe9b7a5675d810d68f03edf0" +dependencies = [ + "utf_types", +] + +[[package]] +name = "utf_types" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a3b425286980a367278453f3b6d28cdcb134b574e5a35824a6ff5eebad50bb6" + +[[package]] +name = "walkdir" +version = "2.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42e295b7452c4604982280d8586001fcad9b8b201cac67bca9771e7a7475403" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + [[package]] name = "wasip2" version = "1.0.1+wasi-0.2.4" @@ -146,12 +1040,224 @@ dependencies = [ "wit-bindgen", ] +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "wit-bindgen" version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "xxhash-rust" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40de123dbb523ebcc00d61ec01840ad192578afc378d859f3429caa38308fad5" + +[[package]] +name = "yoke" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "417ef3fcf6c300b7dbd25c85531a746931c02ad536f3cf4786ed1e88223340b3" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8ebde2db3681e8c9980cc27822030e68752690ddfa9473e739aeb4dbde6d71" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cba8a86aee14fc8cc6c208af60854b3d4ab7185a9a369a12c648faa2716ff42a" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f89bca3b96ceb3cfcb4572790402f977442270d252b9a8504ebc258760c55f94" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85ccff8a4805aba1eaa4cd4afcd49f7557dd2cf5fd79ffc37f8959466effc5aa" + +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f58a2799cfe9a1670c7ea8edbd52ef8edb93cb37a7f83bf31ba9e35d9dae6a40" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3743ddbf47738d929cd1ae2e199d40d0162979dfe31aef8ae646d2bf00bf97a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + [[package]] name = "zmij" version = "1.0.23" diff --git a/README.md b/README.md index 9d5703d..ff3d062 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,47 @@ The full standard is documented at **[babelqueue.com](https://babelqueue.com)**. -> **Status: work in progress, not yet published.** This repository currently holds the -> workspace skeleton, CI and the vendored conformance suite. The codec, the runtime and the -> Redis transport land next; the first release is `0.1.0`. +## Install + +```bash +cargo add babelqueue babelqueue-redis serde_json +cargo add tokio --features macros,rt-multi-thread +``` + +`babelqueue` is the runtime-free core (envelope codec, `App`, in-memory transport); +`babelqueue-redis` adds the Redis transport and needs `tokio`. Use `babelqueue` alone to read and +write envelopes, or to plug in your own `Transport`. + +## Quick start + +```rust +use babelqueue::{App, HandlerError}; +use babelqueue_redis::RedisTransport; +use serde_json::{Value, json}; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let transport = RedisTransport::connect("redis://localhost:6379/0").await?; + let mut app = App::new(transport).queue("orders"); + + // Identity is the URN, never a class name: a Laravel, Python or Go producer sends the same one. + app.handle("urn:babel:orders:created", |env, _delivery| async move { + let data: Value = env.data().map_err(|e| HandlerError::msg(e.to_string()))?; + println!("order {} (produced by {})", data["order_id"], env.meta().lang()); + Ok(()) + }); + + app.publish("urn:babel:orders:created", &json!({ "order_id": 1042 })).await?; + app.drain("orders", 0).await?; // or `app.run(shutdown)` for a long-running worker + Ok(()) +} +``` + +The Redis transport defaults to the Laravel-compatible zset layout (`queues:`), so a Laravel +`babelqueue-redis` connection and the other SDKs' Redis transports share the queue; the legacy +reliable-queue layout is `Options::layout(Layout::Legacy)`. The `redis-orders` example in +[babelqueue-examples](https://github.com/BabelQueue/babelqueue-examples) runs a PHP (Laravel +layout) producer against a Rust consumer. ## Workspace diff --git a/crates/babelqueue-redis/Cargo.toml b/crates/babelqueue-redis/Cargo.toml index b48e9b9..4c02520 100644 --- a/crates/babelqueue-redis/Cargo.toml +++ b/crates/babelqueue-redis/Cargo.toml @@ -4,7 +4,9 @@ description = "BabelQueue Redis transport (broker-bindings section 1) for Rust." readme = "../../README.md" version.workspace = true edition.workspace = true -rust-version.workspace = true +# The `redis` crate sets this floor (1.88), above the core's 1.85. Re-verify with `cargo msrv` +# whenever a dependency changes; an MSRV bump is a MINOR (ADR-0041 decision 7). +rust-version = "1.88" license.workspace = true authors.workspace = true repository.workspace = true @@ -12,8 +14,21 @@ homepage.workspace = true keywords.workspace = true categories.workspace = true +[features] +default = [] +# TLS for `rediss://` URLs, through rustls (no C toolchain). +tls-rustls = ["redis/tokio-rustls-comp"] + [dependencies] babelqueue = { version = "0.1.0", path = "../babelqueue" } +getrandom.workspace = true +serde_json.workspace = true +redis = { version = "1.8", default-features = false, features = ["tokio-comp", "connection-manager", "script"] } +tokio = { version = "1", default-features = false, features = ["time"] } +tracing = { version = "0.1", default-features = false, features = ["std"] } + +[dev-dependencies] +tokio = { version = "1", default-features = false, features = ["macros", "rt-multi-thread", "time", "sync"] } [lints] workspace = true diff --git a/crates/babelqueue-redis/src/error.rs b/crates/babelqueue-redis/src/error.rs new file mode 100644 index 0000000..84ee1d1 --- /dev/null +++ b/crates/babelqueue-redis/src/error.rs @@ -0,0 +1,41 @@ +//! Errors of this crate that are not the Redis client's. + +use std::error::Error; +use std::fmt; + +/// An operation the configured layout, or the given input, cannot do. It reaches the caller wrapped +/// in a [`TransportError`](babelqueue::TransportError). +#[derive(Debug, Clone, PartialEq, Eq)] +#[non_exhaustive] +pub enum UsageError { + /// Delayed publishing needs the zset layout: the legacy layout has no delayed set. + DelayNeedsZsetLayout, + /// A body with headers must be UTF-8 to ride inside the legacy header frame. + HeadersNeedUtf8Body, + /// The delivery was not reserved by a Redis transport. + ForeignDelivery, + /// The system random source failed while making a reservation token. + Random(String), + /// Redis answered a reserve with something that is not `{job, reserved}`. + UnexpectedReply(String), +} + +impl fmt::Display for UsageError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::DelayNeedsZsetLayout => { + f.write_str("babelqueue-redis: delayed publish needs the zset layout") + } + Self::HeadersNeedUtf8Body => { + f.write_str("babelqueue-redis: a body with headers must be valid UTF-8") + } + Self::ForeignDelivery => { + f.write_str("babelqueue-redis: the delivery was not reserved by a Redis transport") + } + Self::Random(e) => write!(f, "babelqueue-redis: random source failed: {e}"), + Self::UnexpectedReply(r) => write!(f, "babelqueue-redis: unexpected reserve reply {r}"), + } + } +} + +impl Error for UsageError {} diff --git a/crates/babelqueue-redis/src/frame.rs b/crates/babelqueue-redis/src/frame.rs new file mode 100644 index 0000000..32c98f0 --- /dev/null +++ b/crates/babelqueue-redis/src/frame.rs @@ -0,0 +1,137 @@ +//! The transport-owned header frame of the legacy layout (ADR-0028). +//! +//! A Redis list value has no metadata channel, so out-of-band headers (a W3C `traceparent`, the +//! replay-bypass marker) ride in a small JSON frame that is not the wire envelope: +//! +//! ```text +//! {"__bq_frame":1,"headers":{"traceparent":"00-..."},"body":""} +//! ``` +//! +//! The frozen envelope never carries `__bq_frame`, so its presence tells a frame from a bare +//! envelope. The frame is written only when there are headers; a plain publish stores the bare +//! envelope byte for byte. The zset layout forbids the frame (it would break Laravel workers and +//! the pop script's `cjson` decode), so headers are dropped there. + +use std::collections::HashMap; + +use serde_json::{Map, Value, json}; + +const SENTINEL: &[u8] = b"\"__bq_frame\""; + +/// The value to push for `body` and `headers`: the body verbatim when no header survives (blank +/// keys and blank values are dropped), the frame otherwise. `None` when headers are present but +/// the body is not UTF-8 and so cannot ride inside a JSON string. +pub(crate) fn frame_value(body: &[u8], headers: &HashMap) -> Option> { + let clean: Map = headers + .iter() + .filter(|(k, v)| !k.is_empty() && !v.is_empty()) + .map(|(k, v)| (k.clone(), Value::String(v.clone()))) + .collect(); + if clean.is_empty() { + return Some(body.to_vec()); + } + let body = std::str::from_utf8(body).ok()?; + serde_json::to_vec(&json!({"__bq_frame": 1, "headers": clean, "body": body})).ok() +} + +/// Interprets a stored list value: a frame yields its body and headers, anything else (a bare +/// envelope, a non-JSON value, JSON without the sentinel) is the body with no headers, so queues +/// written by an older version consume unchanged. +pub(crate) fn unframe(value: &[u8]) -> (Vec, HashMap) { + if value.first() != Some(&b'{') || !value.windows(SENTINEL.len()).any(|w| w == SENTINEL) { + return (value.to_vec(), HashMap::new()); + } + let Ok(Value::Object(frame)) = serde_json::from_slice::(value) else { + return (value.to_vec(), HashMap::new()); + }; + let is_frame = frame + .get("__bq_frame") + .and_then(Value::as_f64) + .is_some_and(|v| v != 0.0); + let Some(Value::String(body)) = frame.get("body").filter(|_| is_frame) else { + return (value.to_vec(), HashMap::new()); + }; + let headers = frame + .get("headers") + .and_then(Value::as_object) + .map(|h| { + h.iter() + .filter_map(|(k, v)| Some((k.clone(), v.as_str()?.to_owned()))) + .filter(|(k, v)| !k.is_empty() && !v.is_empty()) + .collect() + }) + .unwrap_or_default(); + (body.clone().into_bytes(), headers) +} + +#[cfg(test)] +mod tests { + use super::*; + + const ENVELOPE: &[u8] = + br#"{"job":"urn:acme:a","trace_id":"t","data":{},"meta":{},"attempts":0}"#; + + fn headers(pairs: &[(&str, &str)]) -> HashMap { + pairs + .iter() + .map(|(k, v)| ((*k).to_owned(), (*v).to_owned())) + .collect() + } + + #[test] + fn no_headers_stores_the_bare_envelope_byte_for_byte() { + assert_eq!(frame_value(ENVELOPE, &HashMap::new()).unwrap(), ENVELOPE); + let blank = headers(&[("", "x"), ("k", "")]); + assert_eq!(frame_value(ENVELOPE, &blank).unwrap(), ENVELOPE); + } + + #[test] + fn headers_round_trip_through_a_frame() { + let h = headers(&[("traceparent", "00-aa-bb-01")]); + let stored = frame_value(ENVELOPE, &h).unwrap(); + assert!(stored.starts_with(b"{\"__bq_frame\":1")); + let (body, got) = unframe(&stored); + assert_eq!(body, ENVELOPE); + assert_eq!(got, h); + } + + #[test] + fn a_bare_envelope_is_not_a_frame() { + let (body, h) = unframe(ENVELOPE); + assert_eq!(body, ENVELOPE); + assert!(h.is_empty()); + } + + #[test] + fn values_that_only_look_like_frames_stay_bare() { + for value in [ + br#"{"__bq_frame":0,"body":"x"}"#.as_slice(), + br#"{"__bq_frame":1}"#, + br#"{"__bq_frame":1,"body":7}"#, + br#"{"__bq_frame": not json"#, + b"plain text", + b"", + ] { + let (body, h) = unframe(value); + assert_eq!(body, value, "{}", String::from_utf8_lossy(value)); + assert!(h.is_empty()); + } + } + + #[test] + fn a_frame_without_headers_has_an_empty_header_map() { + let (body, h) = unframe(br#"{"__bq_frame":1,"body":"{}"}"#); + assert_eq!(body, b"{}"); + assert!(h.is_empty()); + } + + #[test] + fn headers_cannot_ride_with_a_non_utf8_body() { + let h = headers(&[("k", "v")]); + assert!(frame_value(&[0xff, 0xfe], &h).is_none()); + assert_eq!( + frame_value(&[0xff, 0xfe], &HashMap::new()).unwrap(), + vec![0xff, 0xfe] + ); + } +} diff --git a/crates/babelqueue-redis/src/keys.rs b/crates/babelqueue-redis/src/keys.rs new file mode 100644 index 0000000..85d201e --- /dev/null +++ b/crates/babelqueue-redis/src/keys.rs @@ -0,0 +1,113 @@ +//! Key names and the score formula of broker-bindings section 1. + +use std::time::Duration; + +/// Laravel's default Redis queue key prefix. +pub const DEFAULT_KEY_PREFIX: &str = "queues:"; + +/// The default reservation window (Laravel's `retry_after`, 90 s): a reserved member whose deadline +/// has passed is made ready again. +pub const DEFAULT_RETRY_AFTER: Duration = Duration::from_secs(90); + +/// The Redis key names of one logical queue in the zset layout (broker-bindings section 1.1). +#[derive(Debug, Clone, PartialEq, Eq)] +#[non_exhaustive] +pub struct Keys { + /// The ready list: `RPUSH` on produce, `LPOP` inside the reserve script on consume. + pub ready: String, + /// The delayed set, scored by available-at in epoch seconds (section 1.6). + pub delayed: String, + /// The reserved set of in-flight jobs, scored by the `retry_after` deadline (section 1.7). + pub reserved: String, + /// The blocking-pop wake-up list (section 1.6). + pub notify: String, +} + +/// The Redis key names of one logical queue in the legacy reliable-queue layout (section 1.1). +#[derive(Debug, Clone, PartialEq, Eq)] +#[non_exhaustive] +pub struct LegacyKeys { + /// The ready list: produce and consume. + pub ready: String, + /// The processing list of in-flight bodies, moved there by the reserve script. + pub processing: String, + /// The sorted set of `:` members scored by the recovery deadline (section 1.7). + pub deadlines: String, +} + +/// The zset-layout key names of `queue` under `prefix` (`queues:` is Laravel's default). +#[must_use] +pub fn zset_keys(prefix: &str, queue: &str) -> Keys { + let ready = format!("{prefix}{queue}"); + Keys { + delayed: format!("{ready}:delayed"), + reserved: format!("{ready}:reserved"), + notify: format!("{ready}:notify"), + ready, + } +} + +/// The legacy-layout key names of `queue`. +#[must_use] +pub fn legacy_keys(queue: &str) -> LegacyKeys { + LegacyKeys { + ready: queue.to_owned(), + processing: format!("{queue}:processing"), + deadlines: format!("{queue}:processing:deadlines"), + } +} + +/// The one score formula of the contract (`redis_delay`): `floor(now) + ceil(delay)`, whole epoch +/// seconds. `now` is fractional epoch seconds from the client clock. The reservation deadline of a +/// reserve is the same function of `retry_after`. +#[must_use] +pub fn delay_score(now: f64, delay: Duration) -> i64 { + let whole = delay + .as_secs() + .saturating_add(u64::from(delay.subsec_nanos() > 0)); + // `as` saturates on overflow and maps NaN to 0, which is the behaviour wanted for a clock. + (now.floor() as i64).saturating_add(i64::try_from(whole).unwrap_or(i64::MAX)) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn zset_keys_follow_section_1_1() { + let k = zset_keys("queues:", "emails.high"); + assert_eq!(k.ready, "queues:emails.high"); + assert_eq!(k.delayed, "queues:emails.high:delayed"); + assert_eq!(k.reserved, "queues:emails.high:reserved"); + assert_eq!(k.notify, "queues:emails.high:notify"); + } + + #[test] + fn a_custom_prefix_is_used_verbatim() { + assert_eq!(zset_keys("app:", "q").ready, "app:q"); + } + + #[test] + fn legacy_keys_follow_section_1_1() { + let k = legacy_keys("orders"); + assert_eq!(k.ready, "orders"); + assert_eq!(k.processing, "orders:processing"); + assert_eq!(k.deadlines, "orders:processing:deadlines"); + } + + #[test] + fn the_score_is_floor_now_plus_ceil_delay() { + let d = Duration::from_secs_f64; + assert_eq!(delay_score(1000.7, d(1.5)), 1002); + assert_eq!(delay_score(1000.2, d(0.1)), 1001); + assert_eq!(delay_score(1000.5, d(3.0)), 1003); + assert_eq!(delay_score(1000.0, Duration::ZERO), 1000); + assert_eq!(delay_score(1000.0, Duration::from_nanos(1)), 1001); + } + + #[test] + fn a_degenerate_clock_cannot_overflow_the_score() { + assert_eq!(delay_score(f64::NAN, Duration::from_secs(2)), 2); + assert_eq!(delay_score(f64::MAX, Duration::from_secs(2)), i64::MAX); + } +} diff --git a/crates/babelqueue-redis/src/lib.rs b/crates/babelqueue-redis/src/lib.rs index d3bdb1d..25103b7 100644 --- a/crates/babelqueue-redis/src/lib.rs +++ b/crates/babelqueue-redis/src/lib.rs @@ -1,19 +1,48 @@ //! BabelQueue Redis transport (broker-bindings section 1) for Rust. //! -//! This crate is a skeleton; the transport lands in a later phase of the Rust -//! SDK plan (ADR-0041). +//! [`RedisTransport`] implements the core's [`Transport`](babelqueue::Transport) over Redis, with +//! both layouts of section 1.1: +//! +//! * [`Layout::Zset`] (the default): Laravel's `queues:` layout with `:delayed`, `:reserved` +//! and `:notify`, Laravel's pop script, delayed publishing and in-place release. A queue in this +//! layout is shared with Laravel workers and with the other SDKs' zset transports. +//! * [`Layout::Legacy`]: the reliable-queue layout (``, `:processing`, +//! `:processing:deadlines`) with the token-gated settle and the sweep of section 1.7. +//! +//! ```no_run +//! # async fn demo() -> Result<(), Box> { +//! use babelqueue::App; +//! use babelqueue_redis::RedisTransport; +//! +//! let transport = RedisTransport::connect("redis://localhost:6379/0").await?; +//! let app = App::new(transport).queue("orders").with_releaser().with_dead_letter_settler(); +//! # let _ = app; +//! # Ok(()) +//! # } +//! ``` +//! +//! `retry_after` defaults to 90 s (see [`Options::retry_after`]): keep the handler timeout shorter, +//! or a message that is still being processed is recovered and processed twice. Redis Cluster needs +//! a hash tag in the queue name (`{orders}`), chosen by the caller (section 1.5). +//! +//! Enable the `tls-rustls` feature for `rediss://` URLs. #![forbid(unsafe_code)] -/// The core crate's wire `schema_version`, re-exported so the skeleton links the core. -pub const SCHEMA_VERSION: u32 = babelqueue::SCHEMA_VERSION; +mod error; +mod frame; +mod keys; +mod options; +mod scripts; +mod transport; -#[cfg(test)] -mod tests { - use super::*; +pub use error::UsageError; +pub use keys::{ + DEFAULT_KEY_PREFIX, DEFAULT_RETRY_AFTER, Keys, LegacyKeys, delay_score, legacy_keys, zset_keys, +}; +pub use options::{Layout, Options}; +pub use transport::RedisTransport; - #[test] - fn links_the_core() { - assert_eq!(SCHEMA_VERSION, 1); - } -} +/// The Redis client types that appear in this crate's API, re-exported so a caller need not depend +/// on a matching `redis` version to name them. +pub use redis::{Client, RedisError}; diff --git a/crates/babelqueue-redis/src/options.rs b/crates/babelqueue-redis/src/options.rs new file mode 100644 index 0000000..b84c75a --- /dev/null +++ b/crates/babelqueue-redis/src/options.rs @@ -0,0 +1,166 @@ +//! Configuration of a [`RedisTransport`](crate::RedisTransport). + +use std::fmt; +use std::num::NonZeroU32; +use std::sync::Arc; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; + +use crate::keys::{DEFAULT_KEY_PREFIX, DEFAULT_RETRY_AFTER}; + +/// Which of the two Redis layouts of broker-bindings section 1.1 a transport speaks. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +#[non_exhaustive] +pub enum Layout { + /// Laravel's layout, canonical and the default here: `queues:` plus `:delayed`, + /// `:reserved` and `:notify`. A queue in this layout is shared with Laravel workers and the + /// other SDKs' zset transports, and supports delayed messages and in-place release. + #[default] + Zset, + /// The legacy reliable-queue layout: ``, `:processing` and + /// `:processing:deadlines`. It has no delayed set. + Legacy, +} + +/// The clock of a transport: fractional epoch seconds. +pub(crate) type Clock = Arc f64 + Send + Sync>; + +/// Settings of a [`RedisTransport`](crate::RedisTransport). Build one with [`Options::new`] and the +/// builder methods; every setting has the default of the contract. +#[derive(Clone)] +pub struct Options { + pub(crate) layout: Layout, + pub(crate) key_prefix: String, + pub(crate) retry_after: Option, + pub(crate) migration_batch_size: Option, + pub(crate) response_timeout: Duration, + pub(crate) clock: Clock, +} + +impl Options { + /// The defaults: zset layout, key prefix `queues:`, `retry_after` 90 s, no migration batch + /// limit, a 5 s response timeout and the system clock. + #[must_use] + pub fn new() -> Self { + Self { + layout: Layout::default(), + key_prefix: DEFAULT_KEY_PREFIX.to_owned(), + retry_after: Some(DEFAULT_RETRY_AFTER), + migration_batch_size: None, + response_timeout: Duration::from_secs(5), + clock: Arc::new(wall_clock), + } + } + + /// Selects the layout (default [`Layout::Zset`]). + #[must_use] + pub fn layout(mut self, layout: Layout) -> Self { + self.layout = layout; + self + } + + /// The key prefix of the zset layout (default `queues:`). The queue name is used as given: + /// the SDK neither adds nor removes braces, so a Redis Cluster hash tag is the caller's choice + /// (section 1.5). + #[must_use] + pub fn key_prefix(mut self, prefix: impl Into) -> Self { + self.key_prefix = prefix.into(); + self + } + + /// The reservation window (default 90 s). In the zset layout an expired `:reserved` member is + /// made ready again and counts as an attempt; in the legacy layout an expired deadline member + /// is swept back to the ready list. A [`Duration`] cannot be negative, which is how the + /// contract's "a negative value is a configuration error" holds here. + #[must_use] + pub fn retry_after(mut self, window: Duration) -> Self { + self.retry_after = Some(window); + self + } + + /// The `retry_after: null` setting: this consumer never recovers expired `:reserved` members + /// (zset layout) and its legacy deadline members score `+inf`. It still sweeps other + /// consumers' expired legacy members. + #[must_use] + pub fn without_retry_after(mut self) -> Self { + self.retry_after = None; + self + } + + /// Bounds how many members one migrate (zset) or sweep (legacy) moves; the default is no + /// limit (`migration_batch_size: -1`). + #[must_use] + pub fn migration_batch_size(mut self, limit: NonZeroU32) -> Self { + self.migration_batch_size = Some(limit); + self + } + + /// How long a command may take before the connection reports a timeout (default 5 s). + #[must_use] + pub fn response_timeout(mut self, timeout: Duration) -> Self { + self.response_timeout = timeout; + self + } + + /// Replaces the clock with `clock`, which returns fractional epoch seconds. The score of a + /// delayed message, a reservation deadline and every migrate use it; it exists so tests can pin + /// time, as the conformance suite does. + #[must_use] + pub fn clock(mut self, clock: impl Fn() -> f64 + Send + Sync + 'static) -> Self { + self.clock = Arc::new(clock); + self + } +} + +impl Default for Options { + fn default() -> Self { + Self::new() + } +} + +impl fmt::Debug for Options { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Options") + .field("layout", &self.layout) + .field("key_prefix", &self.key_prefix) + .field("retry_after", &self.retry_after) + .field("migration_batch_size", &self.migration_batch_size) + .field("response_timeout", &self.response_timeout) + .finish_non_exhaustive() + } +} + +fn wall_clock() -> f64 { + SystemTime::now() + .duration_since(UNIX_EPOCH) + .map_or(0.0, |d| d.as_secs_f64()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn the_defaults_are_the_zset_layout_with_a_90_second_window() { + let options = Options::default(); + assert_eq!(options.layout, Layout::Zset); + assert_eq!(Layout::default(), Layout::Zset); + assert_eq!(options.key_prefix, "queues:"); + assert_eq!(options.retry_after, Some(Duration::from_secs(90))); + assert_eq!(options.migration_batch_size, None); + } + + #[test] + fn retry_after_can_be_disabled_and_set_again() { + let options = Options::new() + .without_retry_after() + .retry_after(Duration::from_secs(5)); + assert_eq!(options.retry_after, Some(Duration::from_secs(5))); + assert_eq!(Options::new().without_retry_after().retry_after, None); + } + + #[test] + fn a_pinned_clock_is_what_now_returns() { + let options = Options::new().clock(|| 1234.5); + assert!((options.clock)().to_bits() == 1234.5_f64.to_bits()); + } +} diff --git a/crates/babelqueue-redis/src/scripts.rs b/crates/babelqueue-redis/src/scripts.rs new file mode 100644 index 0000000..91a276a --- /dev/null +++ b/crates/babelqueue-redis/src/scripts.rs @@ -0,0 +1,175 @@ +//! The Lua scripts of broker-bindings section 1. The zset pop script is Laravel's, with the +//! `pcall` guards of ADR-0033 (the same text as `babelqueue-python`'s `redis_transport.py`); the +//! legacy scripts are section 1.7. They run through [`redis::Script`], which sends `EVALSHA` and +//! loads the script then repeats the call on `NOSCRIPT`. + +use std::sync::LazyLock; + +use redis::Script; + +/// KEYS: ready, notify. ARGV: body. Produce in the zset layout: push and signal. +pub(crate) static PUSH: LazyLock