risedev/task/
task_tcp_ready_check.rs1use anyhow::{Context, Result};
16
17use super::{ExecuteContext, Task};
18
19pub struct TcpReadyCheckTask {
23    advertise_address: String,
24    port: u16,
25    user_managed: bool,
26}
27
28impl TcpReadyCheckTask {
29    pub fn new(advertise_address: String, port: u16, user_managed: bool) -> Result<Self> {
30        Ok(Self {
31            advertise_address,
32            port,
33            user_managed,
34        })
35    }
36}
37
38impl Task for TcpReadyCheckTask {
39    fn execute(&mut self, ctx: &mut ExecuteContext<impl std::io::Write>) -> anyhow::Result<()> {
40        let Some(id) = ctx.id.clone() else {
41            panic!("Service should be set before executing TcpReadyCheckTask");
42        };
43        let address = format!("{}:{}", self.advertise_address, self.port);
44
45        if self.user_managed {
46            ctx.pb.set_message(
47                "waiting for user-managed service online... (see `risedev.log` for cli args)",
48            );
49            ctx.wait_tcp_user(&address).with_context(|| {
50                format!("failed to wait for user-managed service `{id}` to be online")
51            })?;
52        } else {
53            ctx.pb.set_message("waiting for online...");
54            ctx.wait_tcp(&address)
55                .with_context(|| format!("failed to wait for service `{id}` to be online"))?;
56        }
57
58        ctx.complete_spin();
59
60        Ok(())
61    }
62}