Skip to content

Commit 40aba26

Browse files
author
Misha
authored
[Feature] A new graphman command to restart a subgraph (#4742)
node : Add new graphman command to restart a subgraph
1 parent 80aa2b0 commit 40aba26

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- `graphman` now has two new commands `pause` and `resume` that can be used to pause and resume a deployment
88
- A new table `subgraph_features` is added which tracks information like spec_version, api_version, network, features, datasources etc
99
- The schema for the `subgraphFeatures` endpoint now includes data from the `subgraph_features` table
10+
- `graphman` now has new command `restart` that can be used to sequentially pause and resume a deployment
1011

1112
<!--
1213
Note: the changes in this PR were technically released in v0.31.0, but the feature also requires changes to graph-cli, which at the time of writing has NOT been released. This feature will make it into the release notes of graph-node only once graph-cli has been updated.

node/src/bin/manager.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,19 @@ pub enum Command {
169169
/// The deployment (see `help info`)
170170
deployment: DeploymentSearch,
171171
},
172+
/// Pause and resume a deployment
173+
Restart {
174+
/// The deployment (see `help info`)
175+
deployment: DeploymentSearch,
176+
/// Sleep for this many seconds after pausing subgraphs
177+
#[clap(
178+
long,
179+
short,
180+
default_value = "20",
181+
parse(try_from_str = parse_duration_in_secs)
182+
)]
183+
sleep: Duration,
184+
},
172185
/// Rewind a subgraph to a specific block
173186
Rewind {
174187
/// Force rewinding even if the block hash is not found in the local
@@ -1120,6 +1133,10 @@ async fn main() -> anyhow::Result<()> {
11201133
let sender = ctx.notification_sender();
11211134
commands::assign::pause_or_resume(ctx.primary_pool(), &sender, &deployment, false)
11221135
}
1136+
Restart { deployment, sleep } => {
1137+
let sender = ctx.notification_sender();
1138+
commands::assign::restart(ctx.primary_pool(), &sender, &deployment, sleep)
1139+
}
11231140
Rewind {
11241141
force,
11251142
sleep,

node/src/manager/commands/assign.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use graph::prelude::{anyhow::anyhow, Error, NodeId, StoreEvent};
22
use graph_store_postgres::{
33
command_support::catalog, connection_pool::ConnectionPool, NotificationSender,
44
};
5+
use std::thread;
6+
use std::time::Duration;
57

68
use crate::manager::deployment::DeploymentSearch;
79

@@ -109,3 +111,19 @@ pub fn pause_or_resume(
109111

110112
Ok(())
111113
}
114+
115+
pub fn restart(
116+
primary: ConnectionPool,
117+
sender: &NotificationSender,
118+
search: &DeploymentSearch,
119+
sleep: Duration,
120+
) -> Result<(), Error> {
121+
pause_or_resume(primary.clone(), sender, search, true)?;
122+
println!(
123+
"Waiting {}s to make sure pausing was processed",
124+
sleep.as_secs()
125+
);
126+
thread::sleep(sleep);
127+
pause_or_resume(primary, sender, search, false)?;
128+
Ok(())
129+
}

0 commit comments

Comments
 (0)