mirror of https://github.com/fralalonde/dipstick
Justfile replaces Makefile. Clippy fixes: socket retry exponential backoff calculation
This commit is contained in:
parent
37c7d806ea
commit
87af3724f1
|
@ -8,6 +8,9 @@
|
||||||
- Dropped .travis.yml. Trav's dead, baby.
|
- Dropped .travis.yml. Trav's dead, baby.
|
||||||
- Revalidated full build after overdue `cargo update`
|
- Revalidated full build after overdue `cargo update`
|
||||||
|
|
||||||
|
## version 0.9.1
|
||||||
|
- Fix bugs
|
||||||
|
|
||||||
## version 0.9.0
|
## version 0.9.0
|
||||||
- Abandon custom Result type and error module in favor
|
- Abandon custom Result type and error module in favor
|
||||||
of io::Result usage across all API. (Based on @rtyler's comment in #80)
|
of io::Result usage across all API. (Based on @rtyler's comment in #80)
|
||||||
|
|
40
Makefile
40
Makefile
|
@ -1,40 +0,0 @@
|
||||||
#!make
|
|
||||||
|
|
||||||
# Why put a makefile in a Cargo project?
|
|
||||||
# To collect the recipes that require several cargo invocations and / or special flags.
|
|
||||||
# Maybe I should write a tool for this...
|
|
||||||
|
|
||||||
# SCCACHE can be 'local' or 'off' (default)
|
|
||||||
# local will cache in ~/.cache/sccache
|
|
||||||
SCCACHE ?= off
|
|
||||||
SCCACHE_CMD ?= ~/.cargo/bin/sccache
|
|
||||||
|
|
||||||
CARGO_CMD ?= $(if $(filter off,$(SCCACHE)),,RUSTC_WRAPPER=$(SCCACHE_CMD) )cargo
|
|
||||||
|
|
||||||
# Default target
|
|
||||||
all: test examples bench
|
|
||||||
|
|
||||||
CARGO_TEST_FLAGS ?=
|
|
||||||
CARGO_BUILD_FLAGS ?=
|
|
||||||
|
|
||||||
# 'test' is a friendly alias for 'unit_test'
|
|
||||||
test:
|
|
||||||
$(CARGO_CMD) test --no-default-features --features="skeptic"
|
|
||||||
|
|
||||||
examples:
|
|
||||||
$(CARGO_CMD) build --examples
|
|
||||||
|
|
||||||
bench:
|
|
||||||
$(CARGO_CMD) +nightly bench --features="bench"
|
|
||||||
|
|
||||||
lint:
|
|
||||||
$(CARGO_CMD) clippy
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(CARGO_CMD) clean
|
|
||||||
|
|
||||||
publish: test examples bench lint
|
|
||||||
cargo publish
|
|
||||||
|
|
||||||
.PHONY: all build clean test examples bench publish
|
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!just
|
||||||
|
# Sane make-like command runner: https://github.com/casey/just
|
||||||
|
|
||||||
|
# Default target
|
||||||
|
all: format test examples bench lint
|
||||||
|
|
||||||
|
# Unit and doc tests
|
||||||
|
test:
|
||||||
|
cargo test --no-default-features --features="skeptic"
|
||||||
|
|
||||||
|
examples:
|
||||||
|
cargo build --examples
|
||||||
|
|
||||||
|
bench:
|
||||||
|
cargo +nightly bench --features="bench"
|
||||||
|
|
||||||
|
format:
|
||||||
|
cargo fmt
|
||||||
|
|
||||||
|
lint:
|
||||||
|
cargo clippy
|
||||||
|
|
||||||
|
clean:
|
||||||
|
cargo clean
|
||||||
|
|
||||||
|
# Build all and then publish to crates.io.
|
||||||
|
publish: all
|
||||||
|
cargo publish
|
|
@ -31,9 +31,11 @@ impl RetrySocket {
|
||||||
// FIXME instead of collecting addresses early, store ToSocketAddrs as trait object
|
// FIXME instead of collecting addresses early, store ToSocketAddrs as trait object
|
||||||
// FIXME apparently this can not be one because of Associated Types clusterfuck (?!)
|
// FIXME apparently this can not be one because of Associated Types clusterfuck (?!)
|
||||||
let addresses = addresses.to_socket_addrs()?.collect();
|
let addresses = addresses.to_socket_addrs()?.collect();
|
||||||
|
const INIT_DELAY: Duration = Duration::from_millis(MIN_RECONNECT_DELAY_MS);
|
||||||
|
let next_try = Instant::now().checked_add(INIT_DELAY).expect("init delay");
|
||||||
let mut socket = RetrySocket {
|
let mut socket = RetrySocket {
|
||||||
retries: 0,
|
retries: 0,
|
||||||
next_try: Instant::now() - Duration::from_millis(MIN_RECONNECT_DELAY_MS),
|
next_try,
|
||||||
addresses,
|
addresses,
|
||||||
socket: None,
|
socket: None,
|
||||||
};
|
};
|
||||||
|
@ -63,12 +65,14 @@ impl RetrySocket {
|
||||||
fn backoff(&mut self, e: io::Error) -> io::Error {
|
fn backoff(&mut self, e: io::Error) -> io::Error {
|
||||||
self.socket = None;
|
self.socket = None;
|
||||||
self.retries += 1;
|
self.retries += 1;
|
||||||
let delay = MAX_RECONNECT_DELAY_MS.min(MIN_RECONNECT_DELAY_MS << self.retries);
|
// double the delay with each retry
|
||||||
|
let exp_delay = MIN_RECONNECT_DELAY_MS << self.retries;
|
||||||
|
let max_delay = MAX_RECONNECT_DELAY_MS.min(exp_delay);
|
||||||
warn!(
|
warn!(
|
||||||
"Could not connect to {:?} after {} trie(s). Backing off reconnection by {}ms. {}",
|
"Could not connect to {:?} after {} trie(s). Backing off reconnection by {}ms. {}",
|
||||||
self.addresses, self.retries, delay, e
|
self.addresses, self.retries, exp_delay, e
|
||||||
);
|
);
|
||||||
self.next_try = Instant::now() + Duration::from_millis(delay);
|
self.next_try = Instant::now() + Duration::from_millis(max_delay);
|
||||||
e
|
e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ impl Scheduler {
|
||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
let mut wait_for = MIN_DELAY;
|
let mut wait_for = MIN_DELAY;
|
||||||
while let Some(sss) = sched1.upgrade() {
|
while let Some(sss) = sched1.upgrade() {
|
||||||
let &(ref heap_mutex, ref condvar) = &*sss;
|
let (heap_mutex, condvar) = &*sss;
|
||||||
let heap = heap_mutex.lock().unwrap();
|
let heap = heap_mutex.lock().unwrap();
|
||||||
let (mut tasks, _timed_out) = condvar.wait_timeout(heap, wait_for).unwrap();
|
let (mut tasks, _timed_out) = condvar.wait_timeout(heap, wait_for).unwrap();
|
||||||
'work: loop {
|
'work: loop {
|
||||||
|
|
Loading…
Reference in New Issue