Skip to content

Commit 56ec0d7

Browse files
committed
Align batch logger API closer to logging
`publish_batch` accepts a mutable reference to an option instead of a mutable reference to a container. Signed-off-by: Moritz Hoffmann <[email protected]>
1 parent 77f96ae commit 56ec0d7

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

timely/src/logging.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@ pub type TimelyProgressLogger = crate::logging_core::Logger<TimelyProgressEventB
1414
use std::time::Duration;
1515
use columnar::Columnar;
1616
use serde::{Deserialize, Serialize};
17+
18+
use crate::Container;
1719
use crate::container::CapacityContainerBuilder;
1820
use crate::dataflow::operators::capture::{Event, EventPusher};
1921

2022
/// Logs events as a timely stream, with progress statements.
21-
pub struct BatchLogger<T, P> where P: EventPusher<Duration, Vec<(Duration, T)>> {
22-
// None when the logging stream is closed
23+
pub struct BatchLogger<P, C> where P: EventPusher<Duration, C> {
2324
time: Duration,
2425
event_pusher: P,
25-
_phantom: ::std::marker::PhantomData<T>,
26+
_phantom: ::std::marker::PhantomData<C>,
2627
}
2728

28-
impl<T, P> BatchLogger<T, P> where P: EventPusher<Duration, Vec<(Duration, T)>> {
29+
impl<P, C> BatchLogger<P, C> where P: EventPusher<Duration, C>, C: Container {
2930
/// Creates a new batch logger.
3031
pub fn new(event_pusher: P) -> Self {
3132
BatchLogger {
@@ -35,8 +36,8 @@ impl<T, P> BatchLogger<T, P> where P: EventPusher<Duration, Vec<(Duration, T)>>
3536
}
3637
}
3738
/// Publishes a batch of logged events and advances the capability.
38-
pub fn publish_batch(&mut self, &time: &Duration, data: &mut Vec<(Duration, T)>) {
39-
if !data.is_empty() {
39+
pub fn publish_batch(&mut self, &time: &Duration, data: &mut Option<C>) {
40+
if let Some(data) = data {
4041
self.event_pusher.push(Event::Messages(self.time, std::mem::take(data)));
4142
}
4243
if self.time < time {
@@ -47,7 +48,7 @@ impl<T, P> BatchLogger<T, P> where P: EventPusher<Duration, Vec<(Duration, T)>>
4748
self.time = time;
4849
}
4950
}
50-
impl<T, P> Drop for BatchLogger<T, P> where P: EventPusher<Duration, Vec<(Duration, T)>> {
51+
impl<P, C> Drop for BatchLogger<P, C> where P: EventPusher<Duration, C> {
5152
fn drop(&mut self) {
5253
self.event_pusher.push(Event::Progress(vec![(self.time, -1)]));
5354
}

0 commit comments

Comments
 (0)