File tree Expand file tree Collapse file tree 5 files changed +42
-9
lines changed
graph/src/components/store
node/src/manager/commands Expand file tree Collapse file tree 5 files changed +42
-9
lines changed Original file line number Diff line number Diff line change @@ -226,7 +226,7 @@ where
226
226
let logger = self . logger . clone ( ) ;
227
227
let node_id = self . node_id . clone ( ) ;
228
228
229
- future:: result ( self . store . assignments ( & self . node_id ) )
229
+ future:: result ( self . store . active_assignments ( & self . node_id ) )
230
230
. map_err ( |e| anyhow ! ( "Error querying subgraph assignments: {}" , e) )
231
231
. and_then ( move |deployments| {
232
232
// This operation should finish only after all subgraphs are
Original file line number Diff line number Diff line change @@ -106,6 +106,9 @@ pub trait SubgraphStore: Send + Sync + 'static {
106
106
107
107
fn assignments ( & self , node : & NodeId ) -> Result < Vec < DeploymentLocator > , StoreError > ;
108
108
109
+ /// Returns assignments that are not paused
110
+ fn active_assignments ( & self , node : & NodeId ) -> Result < Vec < DeploymentLocator > , StoreError > ;
111
+
109
112
/// Return `true` if a subgraph `name` exists, regardless of whether the
110
113
/// subgraph has any deployments attached to it
111
114
fn subgraph_exists ( & self , name : & SubgraphName ) -> Result < bool , StoreError > ;
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ pub fn pause_or_resume(
74
74
primary : ConnectionPool ,
75
75
sender : & NotificationSender ,
76
76
search : & DeploymentSearch ,
77
- pause : bool ,
77
+ should_pause : bool ,
78
78
) -> Result < ( ) , Error > {
79
79
let locator = search. locate_unique ( & primary) ?;
80
80
@@ -86,18 +86,22 @@ pub fn pause_or_resume(
86
86
. ok_or_else ( || anyhow ! ( "failed to locate site for {locator}" ) ) ?;
87
87
88
88
let change = match conn. assignment_status ( & site) ? {
89
- Some ( ( _, paused) ) => {
90
- if paused == pause {
91
- println ! ( "deployment {locator} is already {paused}" ) ;
92
- vec ! [ ]
93
- } else {
89
+ Some ( ( _, is_paused) ) => {
90
+ if should_pause {
91
+ if is_paused {
92
+ println ! ( "deployment {locator} is already paused" ) ;
93
+ return Ok ( ( ) ) ;
94
+ }
94
95
println ! ( "pausing {locator}" ) ;
95
96
conn. pause_subgraph ( & site) ?
97
+ } else {
98
+ println ! ( "resuming {locator}" ) ;
99
+ conn. resume_subgraph ( & site) ?
96
100
}
97
101
}
98
102
None => {
99
- println ! ( "resuming {locator}" ) ;
100
- conn . resume_subgraph ( & site ) ?
103
+ println ! ( "deployment {locator} not found " ) ;
104
+ return Ok ( ( ) ) ;
101
105
}
102
106
} ;
103
107
println ! ( "Operation completed" ) ;
Original file line number Diff line number Diff line change @@ -588,6 +588,22 @@ mod queries {
588
588
. collect :: < Result < Vec < Site > , _ > > ( )
589
589
}
590
590
591
+ // All assignments for a node that are currently not paused
592
+ pub ( super ) fn active_assignments (
593
+ conn : & PgConnection ,
594
+ node : & NodeId ,
595
+ ) -> Result < Vec < Site > , StoreError > {
596
+ ds:: table
597
+ . inner_join ( a:: table. on ( a:: id. eq ( ds:: id) ) )
598
+ . filter ( a:: node_id. eq ( node. as_str ( ) ) )
599
+ . filter ( a:: paused_at. is_null ( ) )
600
+ . select ( ds:: all_columns)
601
+ . load :: < Schema > ( conn) ?
602
+ . into_iter ( )
603
+ . map ( Site :: try_from)
604
+ . collect :: < Result < Vec < Site > , _ > > ( )
605
+ }
606
+
591
607
pub ( super ) fn fill_assignments (
592
608
conn : & PgConnection ,
593
609
infos : & mut [ status:: Info ] ,
@@ -1803,6 +1819,10 @@ impl Mirror {
1803
1819
self . read ( |conn| queries:: assignments ( conn, node) )
1804
1820
}
1805
1821
1822
+ pub fn active_assignments ( & self , node : & NodeId ) -> Result < Vec < Site > , StoreError > {
1823
+ self . read ( |conn| queries:: active_assignments ( conn, node) )
1824
+ }
1825
+
1806
1826
pub fn assigned_node ( & self , site : & Site ) -> Result < Option < NodeId > , StoreError > {
1807
1827
self . read ( |conn| queries:: assigned_node ( conn, site) )
1808
1828
}
Original file line number Diff line number Diff line change @@ -1304,6 +1304,12 @@ impl SubgraphStoreTrait for SubgraphStore {
1304
1304
. map ( |sites| sites. iter ( ) . map ( |site| site. into ( ) ) . collect ( ) )
1305
1305
}
1306
1306
1307
+ fn active_assignments ( & self , node : & NodeId ) -> Result < Vec < DeploymentLocator > , StoreError > {
1308
+ self . mirror
1309
+ . active_assignments ( node)
1310
+ . map ( |sites| sites. iter ( ) . map ( |site| site. into ( ) ) . collect ( ) )
1311
+ }
1312
+
1307
1313
fn subgraph_exists ( & self , name : & SubgraphName ) -> Result < bool , StoreError > {
1308
1314
self . mirror . subgraph_exists ( name)
1309
1315
}
You can’t perform that action at this time.
0 commit comments