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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use crate::types::event_callback::{EventCallback, EventData, EventType};
use async_trait::async_trait;
// This struct represents a user-defined preprocessed callback.
// It can be used to implement custom event handling logic, such as logging or monitoring.
pub struct UserDefinedEventCallback {
pub enable: bool,
}
impl UserDefinedEventCallback {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
// Todo: If you need to enable the callback, set `enable` to `true`
// Lua scripting event callback is disabled if UserDefinedEventCallback is enabled.
Self { enable: false }
}
pub fn is_enabled(&self) -> bool {
self.enable
}
}
#[async_trait]
#[cfg_attr(coverage_nightly, coverage(off))]
impl EventCallback for UserDefinedEventCallback {
// If you want to implement a custom event callback, you can do so by modifying this function.
// The callbacks are called serially, and the callback function MUST return immediately.
// If a callback function takes a long time to execute, it may block a whole pipeline.
#[cfg_attr(coverage_nightly, coverage(off))]
async fn on_event(&mut self, event_data: EventData) {
// Todo: Implement your custom event handling logic here.
match event_data.event_type {
// Sync statistics report events are not captured by the pipeline.
// Maybe there is no need to capture these events
// the pipeline captures only synchronization events.
EventType::PIPELINE_START => {
println!("Pipeline started: {event_data:?}");
}
EventType::PIPELINE_END => {
println!("Pipeline ended: {event_data:?}");
}
// The following events occur per object during the sync process
EventType::SYNC_START => {
println!("Sync started: {event_data:?}");
}
EventType::SYNC_COMPLETE => {
println!("Sync complete: {event_data:?}");
}
EventType::SYNC_DELETE => {
println!("Sync deleted: {event_data:?}");
}
// The following events occur after the SYNC_COMPLETE event
EventType::SYNC_ETAG_VERIFIED => {
println!("Sync ETag verified: {event_data:?}");
}
EventType::SYNC_CHECKSUM_VERIFIED => {
println!("Sync checksum verified: {event_data:?}");
}
EventType::SYNC_ETAG_MISMATCH => {
println!("Sync ETag mismatch: {event_data:?}");
}
EventType::SYNC_CHECKSUM_MISMATCH => {
println!("Sync checksum mismatch: {event_data:?}");
}
// Not all warnings trigger this event, but it is used for general (useful for crate user) warnings
EventType::SYNC_WARNING => {
println!("Sync warning: {event_data:?}");
}
// If an error occurs during the pipeline, this event is triggered and the pipeline is stopped
EventType::PIPELINE_ERROR => {
println!("Pipeline error: {event_data:?}");
}
// If a syncing object is cancelled by preprocess callback, this event is triggered
EventType::SYNC_CANCEL => {
println!("Sync cancelled: {event_data:?}");
}
// If an object (or part of an object) is written, this event is triggered
EventType::SYNC_WRITE => {
println!("Sync write: {event_data:?}");
}
// If an object is filtered out, this event is triggered. EventData.message will contain the reason for filtering.
EventType::SYNC_FILTERED => {
println!("Sync filtered: {event_data:?}");
}
// This event is triggered after the PIPELINE_END event
EventType::STATS_REPORT => {
println!("Stats report: {event_data:?}");
}
// Currently, all events are captured by above match arms,
_ => {
println!("Other events: {event_data:?}");
}
}
}
}