Skip to content

Commit 0e3ee1e

Browse files
committed
Fixed timedelta API.
1 parent dbf56ec commit 0e3ee1e

File tree

11 files changed

+74
-58
lines changed

11 files changed

+74
-58
lines changed

python/natsrpy/_natsrpy_rs/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ class Nats:
100100
*,
101101
domain: str | None = None,
102102
api_prefix: str | None = None,
103-
timeout: timedelta | None = None,
104-
ack_timeout: timedelta | None = None,
103+
timeout: float | timedelta | None = None,
104+
ack_timeout: float | timedelta | None = None,
105105
concurrency_limit: int | None = None,
106106
max_ack_inflight: int | None = None,
107107
backpressure_on_inflight: bool | None = None,

python/natsrpy/_natsrpy_rs/js/consumers.pyi

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class PullConsumerConfig:
8383
delivery_start_sequence: int | None = None,
8484
delivery_start_time: int | None = None,
8585
ack_policy: AckPolicy | None = None,
86-
ack_wait: timedelta | None = None,
86+
ack_wait: float | timedelta | None = None,
8787
max_deliver: int | None = None,
8888
filter_subject: str | None = None,
8989
filter_subjects: list[str] | None = None,
@@ -95,12 +95,12 @@ class PullConsumerConfig:
9595
headers_only: bool | None = None,
9696
max_batch: int | None = None,
9797
max_bytes: int | None = None,
98-
max_expires: timedelta | None = None,
99-
inactive_threshold: timedelta | None = None,
98+
max_expires: float | timedelta | None = None,
99+
inactive_threshold: float | timedelta | None = None,
100100
num_replicas: int | None = None,
101101
memory_storage: bool | None = None,
102102
metadata: dict[str, str] | None = None,
103-
backoff: list[timedelta] | None = None,
103+
backoff: list[float | timedelta] | None = None,
104104
priority_policy: PriorityPolicy | None = None,
105105
priority_groups: list[str] | None = None,
106106
pause_until: int | None = None,
@@ -147,7 +147,7 @@ class PushConsumerConfig:
147147
delivery_start_sequence: int | None = None,
148148
delivery_start_time: int | None = None,
149149
ack_policy: AckPolicy | None = None,
150-
ack_wait: timedelta | None = None,
150+
ack_wait: float | timedelta | None = None,
151151
max_deliver: int | None = None,
152152
filter_subject: str | None = None,
153153
filter_subjects: list[str] | None = None,
@@ -158,12 +158,12 @@ class PushConsumerConfig:
158158
max_ack_pending: int | None = None,
159159
headers_only: bool | None = None,
160160
flow_control: bool | None = None,
161-
idle_heartbeat: timedelta | None = None,
161+
idle_heartbeat: float | timedelta | None = None,
162162
num_replicas: int | None = None,
163163
memory_storage: bool | None = None,
164164
metadata: dict[str, str] | None = None,
165-
backoff: list[timedelta] | None = None,
166-
inactive_threshold: timedelta | None = None,
165+
backoff: list[float | timedelta] | None = None,
166+
inactive_threshold: float | timedelta | None = None,
167167
pause_until: int | None = None,
168168
) -> Self: ...
169169

@@ -188,8 +188,8 @@ class PullConsumer:
188188
group: str | None = None,
189189
priority: int | None = None,
190190
max_bytes: int | None = None,
191-
heartbeat: timedelta | None = None,
192-
expires: timedelta | None = None,
191+
heartbeat: float | timedelta | None = None,
192+
expires: float | timedelta | None = None,
193193
min_pending: int | None = None,
194194
min_ack_pending: int | None = None,
195195
timeout: float | timedelta | None = None,

python/natsrpy/_natsrpy_rs/js/kv.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class KVConfig:
9393
description: str | None = None,
9494
max_value_size: int | None = None,
9595
history: int | None = None,
96-
max_age: float | None = None,
96+
max_age: float | timedelta | None = None,
9797
max_bytes: int | None = None,
9898
storage: StorageType | None = None,
9999
num_replicas: int | None = None,
@@ -103,7 +103,7 @@ class KVConfig:
103103
mirror_direct: bool | None = None,
104104
compression: bool | None = None,
105105
placement: Placement | None = None,
106-
limit_markers: float | None = None,
106+
limit_markers: float | timedelta | None = None,
107107
) -> Self: ...
108108

109109
@final

python/natsrpy/_natsrpy_rs/js/stream.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ class StreamConfig:
167167
discard_new_per_subject: bool | None = None,
168168
retention: RetentionPolicy | None = None,
169169
max_consumers: int | None = None,
170-
max_age: timedelta | None = None,
170+
max_age: float | timedelta | None = None,
171171
max_message_size: int | None = None,
172172
storage: StorageType | None = None,
173173
num_replicas: int | None = None,
174174
no_ack: bool | None = None,
175-
duplicate_window: timedelta | None = None,
175+
duplicate_window: float | timedelta | None = None,
176176
template_owner: str | None = None,
177177
sealed: bool | None = None,
178178
description: str | None = None,
@@ -193,7 +193,7 @@ class StreamConfig:
193193
persist_mode: PersistenceMode | None = None,
194194
pause_until: int | None = None,
195195
allow_message_ttl: bool | None = None,
196-
subject_delete_marker_ttl: timedelta | None = None,
196+
subject_delete_marker_ttl: float | timedelta | None = None,
197197
allow_atomic_publish: bool | None = None,
198198
allow_message_schedules: bool | None = None,
199199
allow_message_counter: bool | None = None,

src/js/consumers/pull/config.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::{collections::HashMap, time::Duration};
33
use crate::{
44
exceptions::rust_err::NatsrpyError,
55
js::consumers::common::{AckPolicy, DeliverPolicy, PriorityPolicy, ReplayPolicy},
6+
utils::py_types::TimeValue,
67
};
78

89
#[pyo3::pyclass(from_py_object, get_all, set_all)]
@@ -80,7 +81,7 @@ impl PullConsumerConfig {
8081
delivery_start_sequence: Option<u64>,
8182
delivery_start_time: Option<i64>,
8283
ack_policy: Option<AckPolicy>,
83-
ack_wait: Option<Duration>,
84+
ack_wait: Option<TimeValue>,
8485
max_deliver: Option<i64>,
8586
filter_subject: Option<String>,
8687
filter_subjects: Option<Vec<String>>,
@@ -92,12 +93,12 @@ impl PullConsumerConfig {
9293
headers_only: Option<bool>,
9394
max_batch: Option<i64>,
9495
max_bytes: Option<i64>,
95-
max_expires: Option<Duration>,
96-
inactive_threshold: Option<Duration>,
96+
max_expires: Option<TimeValue>,
97+
inactive_threshold: Option<TimeValue>,
9798
num_replicas: Option<usize>,
9899
memory_storage: Option<bool>,
99100
metadata: Option<HashMap<String, String>>,
100-
backoff: Option<Vec<Duration>>,
101+
backoff: Option<Vec<TimeValue>>,
101102
priority_policy: Option<PriorityPolicy>,
102103
priority_groups: Option<Vec<String>>,
103104
pause_until: Option<i64>,
@@ -114,7 +115,7 @@ impl PullConsumerConfig {
114115

115116
conf.deliver_policy = deliver_policy.unwrap_or_default();
116117
conf.ack_policy = ack_policy.unwrap_or_default();
117-
conf.ack_wait = ack_wait.unwrap_or_default();
118+
conf.ack_wait = ack_wait.unwrap_or_default().into();
118119
conf.max_deliver = max_deliver.unwrap_or_default();
119120
conf.filter_subject = filter_subject.unwrap_or_default();
120121
conf.filter_subjects = filter_subjects.unwrap_or_default();
@@ -126,12 +127,16 @@ impl PullConsumerConfig {
126127
conf.headers_only = headers_only.unwrap_or_default();
127128
conf.max_batch = max_batch.unwrap_or_default();
128129
conf.max_bytes = max_bytes.unwrap_or_default();
129-
conf.max_expires = max_expires.unwrap_or_default();
130-
conf.inactive_threshold = inactive_threshold.unwrap_or_default();
130+
conf.max_expires = max_expires.unwrap_or_default().into();
131+
conf.inactive_threshold = inactive_threshold.unwrap_or_default().into();
131132
conf.num_replicas = num_replicas.unwrap_or_default();
132133
conf.memory_storage = memory_storage.unwrap_or_default();
133134
conf.metadata = metadata.unwrap_or_default();
134-
conf.backoff = backoff.unwrap_or_default();
135+
conf.backoff = backoff
136+
.unwrap_or_default()
137+
.into_iter()
138+
.map(Into::into)
139+
.collect();
135140
conf.priority_policy = priority_policy.unwrap_or_default();
136141
conf.priority_groups = priority_groups.unwrap_or_default();
137142

src/js/consumers/pull/consumer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{sync::Arc, time::Duration};
1+
use std::sync::Arc;
22

33
use futures_util::StreamExt;
44
use pyo3::{Bound, PyAny, Python};
@@ -47,8 +47,8 @@ impl PullConsumer {
4747
group: Option<String>,
4848
priority: Option<usize>,
4949
max_bytes: Option<usize>,
50-
heartbeat: Option<Duration>,
51-
expires: Option<Duration>,
50+
heartbeat: Option<TimeValue>,
51+
expires: Option<TimeValue>,
5252
min_pending: Option<usize>,
5353
min_ack_pending: Option<usize>,
5454
timeout: Option<TimeValue>,
@@ -74,10 +74,10 @@ impl PullConsumer {
7474
fetch_builder = fetch_builder.max_bytes(max_bytes);
7575
}
7676
if let Some(heartbeat) = heartbeat {
77-
fetch_builder = fetch_builder.heartbeat(heartbeat);
77+
fetch_builder = fetch_builder.heartbeat(heartbeat.into());
7878
}
7979
if let Some(expires) = expires {
80-
fetch_builder = fetch_builder.expires(expires);
80+
fetch_builder = fetch_builder.expires(expires.into());
8181
}
8282
if let Some(min_pending) = min_pending {
8383
fetch_builder = fetch_builder.min_pending(min_pending);

src/js/consumers/push/config.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::{collections::HashMap, time::Duration};
33
use crate::{
44
exceptions::rust_err::NatsrpyError,
55
js::consumers::common::{AckPolicy, DeliverPolicy, ReplayPolicy},
6+
utils::py_types::TimeValue,
67
};
78

89
#[pyo3::pyclass(from_py_object, get_all, set_all)]
@@ -81,7 +82,7 @@ impl PushConsumerConfig {
8182
delivery_start_sequence: Option<u64>,
8283
delivery_start_time: Option<i64>,
8384
ack_policy: Option<AckPolicy>,
84-
ack_wait: Option<Duration>,
85+
ack_wait: Option<TimeValue>,
8586
max_deliver: Option<i64>,
8687
filter_subject: Option<String>,
8788
filter_subjects: Option<Vec<String>>,
@@ -92,12 +93,12 @@ impl PushConsumerConfig {
9293
max_ack_pending: Option<i64>,
9394
headers_only: Option<bool>,
9495
flow_control: Option<bool>,
95-
idle_heartbeat: Option<Duration>,
96+
idle_heartbeat: Option<TimeValue>,
9697
num_replicas: Option<usize>,
9798
memory_storage: Option<bool>,
9899
metadata: Option<HashMap<String, String>>,
99-
backoff: Option<Vec<Duration>>,
100-
inactive_threshold: Option<Duration>,
100+
backoff: Option<Vec<TimeValue>>,
101+
inactive_threshold: Option<TimeValue>,
101102
pause_until: Option<i64>,
102103
) -> Self {
103104
Self {
@@ -112,7 +113,7 @@ impl PushConsumerConfig {
112113

113114
deliver_policy: deliver_policy.unwrap_or_default(),
114115
ack_policy: ack_policy.unwrap_or_default(),
115-
ack_wait: ack_wait.unwrap_or_default(),
116+
ack_wait: ack_wait.unwrap_or_default().into(),
116117
max_deliver: max_deliver.unwrap_or_default(),
117118
filter_subject: filter_subject.unwrap_or_default(),
118119
filter_subjects: filter_subjects.unwrap_or_default(),
@@ -123,12 +124,16 @@ impl PushConsumerConfig {
123124
max_ack_pending: max_ack_pending.unwrap_or_default(),
124125
headers_only: headers_only.unwrap_or_default(),
125126
flow_control: flow_control.unwrap_or_default(),
126-
idle_heartbeat: idle_heartbeat.unwrap_or_default(),
127+
idle_heartbeat: idle_heartbeat.unwrap_or_default().into(),
127128
num_replicas: num_replicas.unwrap_or_default(),
128129
memory_storage: memory_storage.unwrap_or_default(),
129130
metadata: metadata.unwrap_or_default(),
130-
backoff: backoff.unwrap_or_default(),
131-
inactive_threshold: inactive_threshold.unwrap_or_default(),
131+
backoff: backoff
132+
.unwrap_or_default()
133+
.into_iter()
134+
.map(Into::into)
135+
.collect(),
136+
inactive_threshold: inactive_threshold.unwrap_or_default().into(),
132137
}
133138
}
134139
}

src/js/kv.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ impl KVConfig {
6161
limit_markers=None,
6262
))]
6363
#[must_use]
64-
pub const fn __new__(
64+
pub fn __new__(
6565
bucket: String,
6666
description: Option<String>,
6767
max_value_size: Option<i32>,
6868
history: Option<i64>,
69-
max_age: Option<Duration>,
69+
max_age: Option<TimeValue>,
7070
max_bytes: Option<i64>,
7171
storage: Option<js::stream::StorageType>,
7272
num_replicas: Option<usize>,
@@ -76,14 +76,14 @@ impl KVConfig {
7676
mirror_direct: Option<bool>,
7777
compression: Option<bool>,
7878
placement: Option<js::stream::Placement>,
79-
limit_markers: Option<Duration>,
79+
limit_markers: Option<TimeValue>,
8080
) -> Self {
8181
Self {
8282
bucket,
8383
description,
8484
max_value_size,
8585
history,
86-
max_age,
86+
max_age: max_age.map(Into::into),
8787
max_bytes,
8888
storage,
8989
num_replicas,
@@ -93,7 +93,7 @@ impl KVConfig {
9393
mirror_direct,
9494
compression,
9595
placement,
96-
limit_markers,
96+
limit_markers: limit_markers.map(Into::into),
9797
}
9898
}
9999
}

src/js/stream.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ pub struct ConsumerLimits {
160160
impl ConsumerLimits {
161161
#[new]
162162
#[must_use]
163-
pub const fn __new__(inactive_threshold: Duration, max_ack_pending: i64) -> Self {
163+
pub fn __new__(inactive_threshold: TimeValue, max_ack_pending: i64) -> Self {
164164
Self {
165-
inactive_threshold,
165+
inactive_threshold: inactive_threshold.into(),
166166
max_ack_pending,
167167
}
168168
}
@@ -595,12 +595,12 @@ impl StreamConfig {
595595
discard_new_per_subject: Option<bool>,
596596
retention: Option<RetentionPolicy>,
597597
max_consumers: Option<i32>,
598-
max_age: Option<Duration>,
598+
max_age: Option<TimeValue>,
599599
max_message_size: Option<i32>,
600600
storage: Option<StorageType>,
601601
num_replicas: Option<usize>,
602602
no_ack: Option<bool>,
603-
duplicate_window: Option<Duration>,
603+
duplicate_window: Option<TimeValue>,
604604
template_owner: Option<String>,
605605
sealed: Option<bool>,
606606
description: Option<String>,
@@ -621,7 +621,7 @@ impl StreamConfig {
621621
persist_mode: Option<PersistenceMode>,
622622
pause_until: Option<i64>,
623623
allow_message_ttl: Option<bool>,
624-
subject_delete_marker_ttl: Option<Duration>,
624+
subject_delete_marker_ttl: Option<TimeValue>,
625625
allow_atomic_publish: Option<bool>,
626626
allow_message_schedules: Option<bool>,
627627
allow_message_counter: Option<bool>,
@@ -640,21 +640,21 @@ impl StreamConfig {
640640
placement,
641641
persist_mode,
642642
pause_until,
643-
subject_delete_marker_ttl,
644643

644+
subject_delete_marker_ttl: subject_delete_marker_ttl.map(Into::into),
645645
max_bytes: max_bytes.unwrap_or_default(),
646646
max_messages: max_messages.unwrap_or_default(),
647647
max_messages_per_subject: max_messages_per_subject.unwrap_or_default(),
648648
discard: discard.unwrap_or_default(),
649649
discard_new_per_subject: discard_new_per_subject.unwrap_or_default(),
650650
retention: retention.unwrap_or_default(),
651651
max_consumers: max_consumers.unwrap_or_default(),
652-
max_age: max_age.unwrap_or_default(),
652+
max_age: max_age.unwrap_or_default().into(),
653653
max_message_size: max_message_size.unwrap_or_default(),
654654
storage: storage.unwrap_or_default(),
655655
num_replicas: num_replicas.unwrap_or_default(),
656656
no_ack: no_ack.unwrap_or_default(),
657-
duplicate_window: duplicate_window.unwrap_or_default(),
657+
duplicate_window: duplicate_window.unwrap_or_default().into(),
658658
template_owner: template_owner.unwrap_or_default(),
659659
sealed: sealed.unwrap_or_default(),
660660
allow_rollup: allow_rollup.unwrap_or_default(),

0 commit comments

Comments
 (0)