@@ -405,6 +405,7 @@ pub fn make_dummy_site(deployment: DeploymentHash, namespace: Namespace, network
405
405
/// mirrored through `Mirror::refresh_tables` and must be queries, i.e.,
406
406
/// read-only
407
407
mod queries {
408
+ use diesel:: data_types:: PgTimestamp ;
408
409
use diesel:: dsl:: { any, exists, sql} ;
409
410
use diesel:: pg:: PgConnection ;
410
411
use diesel:: prelude:: {
@@ -626,6 +627,36 @@ mod queries {
626
627
. transpose ( )
627
628
}
628
629
630
+ /// Returns Option<(node_id,is_paused)> where `node_id` is the node that
631
+ /// the subgraph is assigned to, and `is_paused` is true if the
632
+ /// subgraph is paused.
633
+ /// Returns None if the deployment does not exist.
634
+ pub ( super ) fn assignment_status (
635
+ conn : & PgConnection ,
636
+ site : & Site ,
637
+ ) -> Result < Option < ( NodeId , bool ) > , StoreError > {
638
+ a:: table
639
+ . filter ( a:: id. eq ( site. id ) )
640
+ . select ( ( a:: node_id, a:: paused_at) )
641
+ . first :: < ( String , Option < PgTimestamp > ) > ( conn)
642
+ . optional ( ) ?
643
+ . map ( |( node, ts) | {
644
+ let node_id = NodeId :: new ( & node) . map_err ( |( ) | {
645
+ constraint_violation ! (
646
+ "invalid node id `{}` in assignment for `{}`" ,
647
+ node,
648
+ site. deployment
649
+ )
650
+ } ) ?;
651
+
652
+ match ts {
653
+ Some ( _) => Ok ( ( node_id, true ) ) ,
654
+ None => Ok ( ( node_id, false ) ) ,
655
+ }
656
+ } )
657
+ . transpose ( )
658
+ }
659
+
629
660
pub ( super ) fn version_info (
630
661
conn : & PgConnection ,
631
662
version : & str ,
@@ -981,7 +1012,7 @@ impl<'a> Connection<'a> {
981
1012
}
982
1013
}
983
1014
984
- pub fn pause_subgraph ( & self , site : & Site ) -> Result < ( ) , StoreError > {
1015
+ pub fn pause_subgraph ( & self , site : & Site ) -> Result < Vec < EntityChange > , StoreError > {
985
1016
use subgraph_deployment_assignment as a;
986
1017
987
1018
let conn = self . conn . as_ref ( ) ;
@@ -991,7 +1022,11 @@ impl<'a> Connection<'a> {
991
1022
. execute ( conn) ?;
992
1023
match updates {
993
1024
0 => Err ( StoreError :: DeploymentNotFound ( site. deployment . to_string ( ) ) ) ,
994
- 1 => Ok ( ( ) ) ,
1025
+ 1 => {
1026
+ let change =
1027
+ EntityChange :: for_assignment ( site. into ( ) , EntityChangeOperation :: Removed ) ;
1028
+ Ok ( vec ! [ change] )
1029
+ }
995
1030
_ => {
996
1031
// `id` is the primary key of the subgraph_deployment_assignment table,
997
1032
// and we can therefore only update no or one entry
@@ -1000,7 +1035,7 @@ impl<'a> Connection<'a> {
1000
1035
}
1001
1036
}
1002
1037
1003
- pub fn resume_subgraph ( & self , site : & Site ) -> Result < ( ) , StoreError > {
1038
+ pub fn resume_subgraph ( & self , site : & Site ) -> Result < Vec < EntityChange > , StoreError > {
1004
1039
use subgraph_deployment_assignment as a;
1005
1040
1006
1041
let conn = self . conn . as_ref ( ) ;
@@ -1010,7 +1045,10 @@ impl<'a> Connection<'a> {
1010
1045
. execute ( conn) ?;
1011
1046
match updates {
1012
1047
0 => Err ( StoreError :: DeploymentNotFound ( site. deployment . to_string ( ) ) ) ,
1013
- 1 => Ok ( ( ) ) ,
1048
+ 1 => {
1049
+ let change = EntityChange :: for_assignment ( site. into ( ) , EntityChangeOperation :: Set ) ;
1050
+ Ok ( vec ! [ change] )
1051
+ }
1014
1052
_ => {
1015
1053
// `id` is the primary key of the subgraph_deployment_assignment table,
1016
1054
// and we can therefore only update no or one entry
@@ -1148,6 +1186,14 @@ impl<'a> Connection<'a> {
1148
1186
queries:: assigned_node ( self . conn . as_ref ( ) , site)
1149
1187
}
1150
1188
1189
+ /// Returns Option<(node_id,is_paused)> where `node_id` is the node that
1190
+ /// the subgraph is assigned to, and `is_paused` is true if the
1191
+ /// subgraph is paused.
1192
+ /// Returns None if the deployment does not exist.
1193
+ pub fn assignment_status ( & self , site : & Site ) -> Result < Option < ( NodeId , bool ) > , StoreError > {
1194
+ queries:: assignment_status ( self . conn . as_ref ( ) , site)
1195
+ }
1196
+
1151
1197
/// Create a copy of the site `src` in the shard `shard`, but mark it as
1152
1198
/// not active. If there already is a site in `shard`, return that
1153
1199
/// instead.
@@ -1761,6 +1807,14 @@ impl Mirror {
1761
1807
self . read ( |conn| queries:: assigned_node ( conn, site) )
1762
1808
}
1763
1809
1810
+ /// Returns Option<(node_id,is_paused)> where `node_id` is the node that
1811
+ /// the subgraph is assigned to, and `is_paused` is true if the
1812
+ /// subgraph is paused.
1813
+ /// Returns None if the deployment does not exist.
1814
+ pub fn assignment_status ( & self , site : & Site ) -> Result < Option < ( NodeId , bool ) > , StoreError > {
1815
+ self . read ( |conn| queries:: assignment_status ( conn, site) )
1816
+ }
1817
+
1764
1818
pub fn find_active_site ( & self , subgraph : & DeploymentHash ) -> Result < Option < Site > , StoreError > {
1765
1819
self . read ( |conn| queries:: find_active_site ( conn, subgraph) )
1766
1820
}
0 commit comments