1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use std::io::BufReader;
use std::fs::File;
use std::time::Duration;
use std::path::PathBuf;
pub const DEFAULT_ROTATION_CHECK_WAIT_MILLIS: u64 = 100;
pub const DEFAULT_NOT_ROTATED_WAIT_MILLIS: u64 = 50;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
pub struct Line(pub usize);
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
pub struct Pos(pub u64);
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
pub(crate) struct FileId(pub(crate) u64);
#[derive(Debug, Clone)]
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
pub struct Chaser {
pub line: Line,
pub path: PathBuf,
pub initial_no_file_wait: Duration,
pub initial_no_file_attempts: Option<usize>,
pub rotation_check_wait: Duration,
pub rotation_check_attempts: Option<usize>,
pub not_rotated_wait: Duration,
}
#[derive(Debug)]
pub(crate) struct Chasing<'a> {
pub(crate) chaser: &'a mut Chaser,
pub(crate) file_id: FileId,
pub(crate) reader: BufReader<File>,
pub(crate) buffer: String,
pub(crate) line: Line,
pub(crate) pos: Pos,
}
impl Chaser {
pub fn new<S>(path: S) -> Chaser
where
S: Into<PathBuf>,
{
Chaser {
line: Line(0),
path: path.into(),
initial_no_file_attempts: None,
initial_no_file_wait: Duration::from_millis(DEFAULT_ROTATION_CHECK_WAIT_MILLIS),
rotation_check_attempts: None,
rotation_check_wait: Duration::from_millis(DEFAULT_ROTATION_CHECK_WAIT_MILLIS),
not_rotated_wait: Duration::from_millis(DEFAULT_NOT_ROTATED_WAIT_MILLIS),
}
}
}