-
Notifications
You must be signed in to change notification settings - Fork 371
Expand file tree
/
Copy pathcheckpoint_stopping.rs
More file actions
104 lines (94 loc) · 3.58 KB
/
Copy pathcheckpoint_stopping.rs
File metadata and controls
104 lines (94 loc) · 3.58 KB
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 arroyo_rpc::grpc;
use tracing::debug;
use crate::{JobMessage, states::StateError};
use super::{
JobContext, State, Stopped, Transition,
stopping::{StopBehavior, Stopping},
};
#[derive(Debug)]
pub struct CheckpointStopping {}
#[async_trait::async_trait]
impl State for CheckpointStopping {
fn name(&self) -> &'static str {
"CheckpointStopping"
}
async fn next(mut self: Box<Self>, ctx: &mut JobContext) -> Result<Transition, StateError> {
let job_id = ctx.config.id.clone();
let pipeline_id = ctx.pipeline_info.pipeline_id.clone();
let job_controller = ctx.job_controller.as_mut().unwrap();
let mut final_checkpoint_started = false;
loop {
match job_controller.checkpoint_finished().await {
Ok(done) => {
debug!(
job_id = %job_id,
pipeline_id = *pipeline_id,
"checked checkpoint, got {}, job_controller.finished(): {}, final_checkpoint_started: {}",
done,
job_controller.finished(),
final_checkpoint_started
);
if done && job_controller.finished() && final_checkpoint_started {
return Ok(Transition::next(*self, Stopped {}));
}
}
Err(e) => {
return Err(ctx.retryable(
self,
"failed while monitoring final checkpoint",
e,
10,
));
}
}
if !final_checkpoint_started {
match job_controller.checkpoint(true).await {
Ok(started) => final_checkpoint_started = started,
Err(e) => {
return Err(ctx.retryable(
self,
"failed to initiate final checkpoint",
e,
10,
));
}
}
}
match ctx.rx.recv().await.expect("channel closed while receiving") {
JobMessage::RunningMessage(msg) => {
if let Err(e) = job_controller.handle_message(msg).await {
return Err(ctx.retryable(
self,
"failed while waiting for job finish",
e,
10,
));
}
}
JobMessage::ConfigUpdate(c) => {
match c.stop_mode {
crate::types::public::StopMode::immediate => {
return Ok(Transition::next(
*self,
Stopping {
stop_mode: StopBehavior::StopJob(
grpc::rpc::StopMode::Immediate,
),
},
));
}
crate::types::public::StopMode::force => {
todo!("implement force stop mode");
}
_ => {
// do nothing
}
}
}
_ => {
// ignore other messages
}
}
}
}
}