Skip to content

Commit 506246c

Browse files
committed
chore(ups): handle edge cases with postgres listen/unlisten/notify when disconnected/reconnecting (#2893)
Fixes RVT-5131
1 parent bf38cb9 commit 506246c

File tree

38 files changed

+2519
-1704
lines changed

38 files changed

+2519
-1704
lines changed

Cargo.lock

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/errors/ups.publish_failed.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/common/test-deps-docker/src/lib.rs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,114 @@ impl DockerRunConfig {
7373
Ok(true)
7474
}
7575

76+
pub async fn restart(&self) -> Result<()> {
77+
let container_id = self
78+
.container_id
79+
.as_ref()
80+
.ok_or_else(|| anyhow!("No container ID found, container not started"))?;
81+
82+
tracing::debug!(
83+
container_name = %self.container_name,
84+
container_id = %container_id,
85+
"restarting docker container"
86+
);
87+
88+
let output = Command::new("docker")
89+
.arg("restart")
90+
.arg(container_id)
91+
.output()
92+
.await?;
93+
94+
if !output.status.success() {
95+
let stderr = String::from_utf8_lossy(&output.stderr);
96+
anyhow::bail!(
97+
"Failed to restart container {}: {}",
98+
self.container_name,
99+
stderr
100+
);
101+
}
102+
103+
tracing::debug!(
104+
container_name = %self.container_name,
105+
container_id = %container_id,
106+
"container restarted successfully"
107+
);
108+
109+
Ok(())
110+
}
111+
112+
pub async fn stop_container(&self) -> Result<()> {
113+
let container_id = self
114+
.container_id
115+
.as_ref()
116+
.ok_or_else(|| anyhow!("No container ID found, container not started"))?;
117+
118+
tracing::debug!(
119+
container_name = %self.container_name,
120+
container_id = %container_id,
121+
"stopping docker container"
122+
);
123+
124+
let output = Command::new("docker")
125+
.arg("stop")
126+
.arg(container_id)
127+
.output()
128+
.await?;
129+
130+
if !output.status.success() {
131+
let stderr = String::from_utf8_lossy(&output.stderr);
132+
anyhow::bail!(
133+
"Failed to stop container {}: {}",
134+
self.container_name,
135+
stderr
136+
);
137+
}
138+
139+
tracing::debug!(
140+
container_name = %self.container_name,
141+
container_id = %container_id,
142+
"container stopped successfully"
143+
);
144+
145+
Ok(())
146+
}
147+
148+
pub async fn start_container(&self) -> Result<()> {
149+
let container_id = self
150+
.container_id
151+
.as_ref()
152+
.ok_or_else(|| anyhow!("No container ID found, container not started"))?;
153+
154+
tracing::debug!(
155+
container_name = %self.container_name,
156+
container_id = %container_id,
157+
"starting docker container"
158+
);
159+
160+
let output = Command::new("docker")
161+
.arg("start")
162+
.arg(container_id)
163+
.output()
164+
.await?;
165+
166+
if !output.status.success() {
167+
let stderr = String::from_utf8_lossy(&output.stderr);
168+
anyhow::bail!(
169+
"Failed to start container {}: {}",
170+
self.container_name,
171+
stderr
172+
);
173+
}
174+
175+
tracing::debug!(
176+
container_name = %self.container_name,
177+
container_id = %container_id,
178+
"container started successfully"
179+
);
180+
181+
Ok(())
182+
}
183+
76184
pub fn container_id(&self) -> Option<&str> {
77185
self.container_id.as_deref()
78186
}

packages/common/universalpubsub/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ async-trait.workspace = true
1212
base64.workspace = true
1313
deadpool-postgres.workspace = true
1414
futures-util.workspace = true
15-
moka.workspace = true
1615
rivet-error.workspace = true
1716
rivet-ups-protocol.workspace = true
17+
rivet-util.workspace = true
1818
serde_json.workspace = true
1919
versioned-data-util.workspace = true
2020
serde.workspace = true
2121
sha2.workspace = true
2222
tokio-postgres.workspace = true
2323
tokio.workspace = true
24+
tokio-util.workspace = true
2425
tracing.workspace = true
2526
uuid.workspace = true
2627

0 commit comments

Comments
 (0)