Skip to content

Commit a40af63

Browse files
Naming improvements (#23)
1 parent 0683bff commit a40af63

File tree

11 files changed

+63
-75
lines changed

11 files changed

+63
-75
lines changed

examples/counter.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ impl Counter for CounterImpl {
3838
#[tokio::main]
3939
async fn main() {
4040
tracing_subscriber::fmt::init();
41-
HttpServer::new(
42-
Endpoint::builder()
43-
.with_service(CounterImpl.serve())
44-
.build(),
45-
)
46-
.listen_and_serve("0.0.0.0:9080".parse().unwrap())
47-
.await;
41+
HttpServer::new(Endpoint::builder().bind(CounterImpl.serve()).build())
42+
.listen_and_serve("0.0.0.0:9080".parse().unwrap())
43+
.await;
4844
}

examples/failures.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ impl FailureExample for FailureExampleImpl {
3232
#[tokio::main]
3333
async fn main() {
3434
tracing_subscriber::fmt::init();
35-
HttpServer::new(
36-
Endpoint::builder()
37-
.with_service(FailureExampleImpl.serve())
38-
.build(),
39-
)
40-
.listen_and_serve("0.0.0.0:9080".parse().unwrap())
41-
.await;
35+
HttpServer::new(Endpoint::builder().bind(FailureExampleImpl.serve()).build())
36+
.listen_and_serve("0.0.0.0:9080".parse().unwrap())
37+
.await;
4238
}

examples/greeter.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ impl Greeter for GreeterImpl {
1717
#[tokio::main]
1818
async fn main() {
1919
tracing_subscriber::fmt::init();
20-
HttpServer::new(
21-
Endpoint::builder()
22-
.with_service(GreeterImpl.serve())
23-
.build(),
24-
)
25-
.listen_and_serve("0.0.0.0:9080".parse().unwrap())
26-
.await;
20+
HttpServer::new(Endpoint::builder().bind(GreeterImpl.serve()).build())
21+
.listen_and_serve("0.0.0.0:9080".parse().unwrap())
22+
.await;
2723
}

examples/run.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl RunExample for RunExampleImpl {
2626

2727
Ok(Json::from(res))
2828
})
29-
.named("get_ip")
29+
.name("get_ip")
3030
.await?
3131
.into_inner();
3232

@@ -39,7 +39,7 @@ async fn main() {
3939
tracing_subscriber::fmt::init();
4040
HttpServer::new(
4141
Endpoint::builder()
42-
.with_service(RunExampleImpl(reqwest::Client::new()).serve())
42+
.bind(RunExampleImpl(reqwest::Client::new()).serve())
4343
.build(),
4444
)
4545
.listen_and_serve("0.0.0.0:9080".parse().unwrap())

src/context/run.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,30 @@ pub trait RunFuture<O>: Future<Output = O> {
3131
///
3232
/// If unspecified, the `run` will be retried using the [Restate invoker retry policy](https://docs.restate.dev/operate/configuration/server),
3333
/// which by default retries indefinitely.
34-
fn with_retry_policy(self, retry_policy: RunRetryPolicy) -> Self;
34+
fn retry_policy(self, retry_policy: RunRetryPolicy) -> Self;
3535

3636
/// Define a name for this `run` operation.
3737
///
3838
/// This is used mainly for observability.
39-
fn named(self, name: impl Into<String>) -> Self;
39+
fn name(self, name: impl Into<String>) -> Self;
4040
}
4141

4242
/// This struct represents the policy to execute retries for run closures.
4343
#[derive(Debug, Clone)]
4444
pub struct RunRetryPolicy {
45-
pub(crate) initial_interval: Duration,
45+
pub(crate) initial_delay: Duration,
4646
pub(crate) factor: f32,
47-
pub(crate) max_interval: Option<Duration>,
47+
pub(crate) max_delay: Option<Duration>,
4848
pub(crate) max_attempts: Option<u32>,
4949
pub(crate) max_duration: Option<Duration>,
5050
}
5151

5252
impl Default for RunRetryPolicy {
5353
fn default() -> Self {
5454
Self {
55-
initial_interval: Duration::from_millis(100),
55+
initial_delay: Duration::from_millis(100),
5656
factor: 2.0,
57-
max_interval: Some(Duration::from_secs(2)),
57+
max_delay: Some(Duration::from_secs(2)),
5858
max_attempts: None,
5959
max_duration: Some(Duration::from_secs(50)),
6060
}
@@ -65,29 +65,29 @@ impl RunRetryPolicy {
6565
/// Create a new retry policy.
6666
pub fn new() -> Self {
6767
Self {
68-
initial_interval: Duration::from_millis(100),
68+
initial_delay: Duration::from_millis(100),
6969
factor: 1.0,
70-
max_interval: None,
70+
max_delay: None,
7171
max_attempts: None,
7272
max_duration: None,
7373
}
7474
}
7575

76-
/// Initial interval for the first retry attempt.
77-
pub fn with_initial_interval(mut self, initial_interval: Duration) -> Self {
78-
self.initial_interval = initial_interval;
76+
/// Initial retry delay for the first retry attempt.
77+
pub fn initial_delay(mut self, initial_interval: Duration) -> Self {
78+
self.initial_delay = initial_interval;
7979
self
8080
}
8181

82-
/// Maximum interval between retries.
83-
pub fn with_factor(mut self, factor: f32) -> Self {
82+
/// Exponentiation factor to use when computing the next retry delay.
83+
pub fn exponentiation_factor(mut self, factor: f32) -> Self {
8484
self.factor = factor;
8585
self
8686
}
8787

88-
/// Maximum interval between retries.
89-
pub fn with_max_interval(mut self, max_interval: Duration) -> Self {
90-
self.max_interval = Some(max_interval);
88+
/// Maximum delay between retries.
89+
pub fn max_delay(mut self, max_interval: Duration) -> Self {
90+
self.max_delay = Some(max_interval);
9191
self
9292
}
9393

@@ -98,7 +98,7 @@ impl RunRetryPolicy {
9898
/// This is due to the nature of the run operation, which executes the closure on the service and sends the result afterward to Restate.
9999
///
100100
/// Infinite retries if this field and `max_duration` are unset.
101-
pub fn with_max_attempts(mut self, max_attempts: u32) -> Self {
101+
pub fn max_attempts(mut self, max_attempts: u32) -> Self {
102102
self.max_attempts = Some(max_attempts);
103103
self
104104
}
@@ -110,7 +110,7 @@ impl RunRetryPolicy {
110110
/// This is due to the nature of the run operation, which executes the closure on the service and sends the result afterward to Restate.
111111
///
112112
/// Infinite retries if this field and `max_attempts` are unset.
113-
pub fn with_max_duration(mut self, max_duration: Duration) -> Self {
113+
pub fn max_duration(mut self, max_duration: Duration) -> Self {
114114
self.max_duration = Some(max_duration);
115115
self
116116
}

src/endpoint/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,18 +638,18 @@ where
638638
Fut: Future<Output = HandlerResult<Out>> + Send + Sync,
639639
Out: Serialize + Deserialize,
640640
{
641-
fn with_retry_policy(mut self, retry_policy: RunRetryPolicy) -> Self {
641+
fn retry_policy(mut self, retry_policy: RunRetryPolicy) -> Self {
642642
self.retry_policy = RetryPolicy::Exponential {
643-
initial_interval: retry_policy.initial_interval,
643+
initial_interval: retry_policy.initial_delay,
644644
factor: retry_policy.factor,
645-
max_interval: retry_policy.max_interval,
645+
max_interval: retry_policy.max_delay,
646646
max_attempts: retry_policy.max_attempts,
647647
max_duration: retry_policy.max_duration,
648648
};
649649
self
650650
}
651651

652-
fn named(mut self, name: impl Into<String>) -> Self {
652+
fn name(mut self, name: impl Into<String>) -> Self {
653653
self.name = name.into();
654654
self
655655
}

src/endpoint/futures/intercept_error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ impl<F, R> RunFuture<R> for InterceptErrorFuture<F>
4848
where
4949
F: RunFuture<Result<R, Error>>,
5050
{
51-
fn with_retry_policy(mut self, retry_policy: RunRetryPolicy) -> Self {
52-
self.fut = self.fut.with_retry_policy(retry_policy);
51+
fn retry_policy(mut self, retry_policy: RunRetryPolicy) -> Self {
52+
self.fut = self.fut.retry_policy(retry_policy);
5353
self
5454
}
5555

56-
fn named(mut self, name: impl Into<String>) -> Self {
57-
self.fut = self.fut.named(name);
56+
fn name(mut self, name: impl Into<String>) -> Self {
57+
self.fut = self.fut.name(name);
5858
self
5959
}
6060
}

src/endpoint/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,10 @@ impl Builder {
192192
Self::default()
193193
}
194194

195-
/// Add a service.
195+
/// Add a [`Service`] to this endpoint.
196196
///
197197
/// When using the service/object/workflow macros, you need to pass the result of the `serve` method.
198-
pub fn with_service<
198+
pub fn bind<
199199
S: Service<Future = BoxFuture<'static, Result<(), Error>>>
200200
+ Discoverable
201201
+ Send
@@ -214,7 +214,7 @@ impl Builder {
214214
}
215215

216216
/// Add identity key, e.g. `publickeyv1_ChjENKeMvCtRnqG2mrBK1HmPKufgFUc98K8B3ononQvp`.
217-
pub fn with_identity_key(mut self, key: &str) -> Result<Self, KeyError> {
217+
pub fn identity_key(mut self, key: &str) -> Result<Self, KeyError> {
218218
self.identity_verifier = self.identity_verifier.with_key(key)?;
219219
Ok(self)
220220
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//! async fn main() {
2727
//! HttpServer::new(
2828
//! Endpoint::builder()
29-
//! .with_service(GreeterImpl.serve())
29+
//! .bind(GreeterImpl.serve())
3030
//! .build(),
3131
//! )
3232
//! .listen_and_serve("0.0.0.0:9080".parse().unwrap())

test-services/src/failing.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ impl Failing for FailingImpl {
9595
Err(anyhow!("Failed at attempt {current_attempt}"))?
9696
}
9797
})
98-
.with_retry_policy(
98+
.retry_policy(
9999
RunRetryPolicy::new()
100-
.with_initial_interval(Duration::from_millis(10))
101-
.with_factor(1.0),
100+
.initial_delay(Duration::from_millis(10))
101+
.exponentiation_factor(1.0),
102102
)
103-
.named("failing_side_effect")
103+
.name("failing_side_effect")
104104
.await?;
105105

106106
Ok(success_attempt)
@@ -117,11 +117,11 @@ impl Failing for FailingImpl {
117117
let current_attempt = cloned_counter.fetch_add(1, Ordering::SeqCst) + 1;
118118
Err::<(), _>(anyhow!("Failed at attempt {current_attempt}").into())
119119
})
120-
.with_retry_policy(
120+
.retry_policy(
121121
RunRetryPolicy::new()
122-
.with_initial_interval(Duration::from_millis(10))
123-
.with_factor(1.0)
124-
.with_max_attempts(retry_policy_max_retry_count as u32),
122+
.initial_delay(Duration::from_millis(10))
123+
.exponentiation_factor(1.0)
124+
.max_attempts(retry_policy_max_retry_count as u32),
125125
)
126126
.await
127127
.is_err()

test-services/src/main.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,63 +22,63 @@ async fn main() {
2222
let mut builder = Endpoint::builder();
2323

2424
if services == "*" || services.contains("Counter") {
25-
builder = builder.with_service(counter::Counter::serve(counter::CounterImpl))
25+
builder = builder.bind(counter::Counter::serve(counter::CounterImpl))
2626
}
2727
if services == "*" || services.contains("Proxy") {
28-
builder = builder.with_service(proxy::Proxy::serve(proxy::ProxyImpl))
28+
builder = builder.bind(proxy::Proxy::serve(proxy::ProxyImpl))
2929
}
3030
if services == "*" || services.contains("MapObject") {
31-
builder = builder.with_service(map_object::MapObject::serve(map_object::MapObjectImpl))
31+
builder = builder.bind(map_object::MapObject::serve(map_object::MapObjectImpl))
3232
}
3333
if services == "*" || services.contains("ListObject") {
34-
builder = builder.with_service(list_object::ListObject::serve(list_object::ListObjectImpl))
34+
builder = builder.bind(list_object::ListObject::serve(list_object::ListObjectImpl))
3535
}
3636
if services == "*" || services.contains("AwakeableHolder") {
37-
builder = builder.with_service(awakeable_holder::AwakeableHolder::serve(
37+
builder = builder.bind(awakeable_holder::AwakeableHolder::serve(
3838
awakeable_holder::AwakeableHolderImpl,
3939
))
4040
}
4141
if services == "*" || services.contains("BlockAndWaitWorkflow") {
42-
builder = builder.with_service(block_and_wait_workflow::BlockAndWaitWorkflow::serve(
42+
builder = builder.bind(block_and_wait_workflow::BlockAndWaitWorkflow::serve(
4343
block_and_wait_workflow::BlockAndWaitWorkflowImpl,
4444
))
4545
}
4646
if services == "*" || services.contains("CancelTestRunner") {
47-
builder = builder.with_service(cancel_test::CancelTestRunner::serve(
47+
builder = builder.bind(cancel_test::CancelTestRunner::serve(
4848
cancel_test::CancelTestRunnerImpl,
4949
))
5050
}
5151
if services == "*" || services.contains("CancelTestBlockingService") {
52-
builder = builder.with_service(cancel_test::CancelTestBlockingService::serve(
52+
builder = builder.bind(cancel_test::CancelTestBlockingService::serve(
5353
cancel_test::CancelTestBlockingServiceImpl,
5454
))
5555
}
5656
if services == "*" || services.contains("Failing") {
57-
builder = builder.with_service(failing::Failing::serve(failing::FailingImpl::default()))
57+
builder = builder.bind(failing::Failing::serve(failing::FailingImpl::default()))
5858
}
5959
if services == "*" || services.contains("KillTestRunner") {
60-
builder = builder.with_service(kill_test::KillTestRunner::serve(
60+
builder = builder.bind(kill_test::KillTestRunner::serve(
6161
kill_test::KillTestRunnerImpl,
6262
))
6363
}
6464
if services == "*" || services.contains("KillTestSingleton") {
65-
builder = builder.with_service(kill_test::KillTestSingleton::serve(
65+
builder = builder.bind(kill_test::KillTestSingleton::serve(
6666
kill_test::KillTestSingletonImpl,
6767
))
6868
}
6969
if services == "*" || services.contains("NonDeterministic") {
70-
builder = builder.with_service(non_deterministic::NonDeterministic::serve(
70+
builder = builder.bind(non_deterministic::NonDeterministic::serve(
7171
non_deterministic::NonDeterministicImpl::default(),
7272
))
7373
}
7474
if services == "*" || services.contains("TestUtilsService") {
75-
builder = builder.with_service(test_utils_service::TestUtilsService::serve(
75+
builder = builder.bind(test_utils_service::TestUtilsService::serve(
7676
test_utils_service::TestUtilsServiceImpl,
7777
))
7878
}
7979

8080
if let Ok(key) = env::var("E2E_REQUEST_SIGNING_ENV") {
81-
builder = builder.with_identity_key(&key).unwrap()
81+
builder = builder.identity_key(&key).unwrap()
8282
}
8383

8484
HttpServer::new(builder.build())

0 commit comments

Comments
 (0)