@@ -13,7 +13,7 @@ use uuid::Uuid;
1313
1414use crate :: api:: cluster;
1515use crate :: constants:: PROCESSOR_FILE ;
16- use crate :: proxy:: send:: send_process;
16+ use crate :: proxy:: send:: { send_ingress , send_message , send_process} ;
1717use crate :: proxy:: ProcessPayloadType ;
1818use crate :: utils:: http:: read_json;
1919use crate :: State ;
@@ -427,7 +427,7 @@ impl Processor {
427427
428428 #[ cfg( target_os = "linux" ) ]
429429 {
430- if enable_gamemode. is_some_and ( |x| x == true ) {
430+ if enable_gamemode. is_some_and ( |x| x) {
431431 if let Err ( err) = onelauncher_gamemode:: request_start_for_wrapper ( pid) {
432432 tracing:: warn!( "failed to enable gamemode, continuing: {}" , err) ;
433433 } ;
@@ -654,8 +654,8 @@ impl Processor {
654654 } ) ;
655655
656656 tokio:: spawn ( async {
657- let state = State :: get ( ) ;
658- let state = match state. await {
657+ let state = State :: get ( ) . await ;
658+ let state = match state {
659659 Ok ( state) => state,
660660 Err ( err) => {
661661 tracing:: warn!( "failed to get state: {}" , err) ;
@@ -689,47 +689,59 @@ impl Processor {
689689 }
690690
691691 let post = if let Some ( hook) = post {
692- let mut cmd = hook. split ( ' ' ) ;
693- if let Some ( c) = cmd. next ( ) {
694- let mut c = Command :: new ( c) ;
695- c. args ( cmd) . current_dir ( cluster_path. full_path ( ) . await ?) ;
696- Some ( c)
697- } else {
692+ if hook. is_empty ( ) {
698693 None
694+ } else {
695+ let mut cmd = hook. split ( ' ' ) ;
696+ if let Some ( c) = cmd. next ( ) {
697+ let mut c = Command :: new ( c) ;
698+ c. args ( cmd) . current_dir ( cluster_path. full_path ( ) . await ?) ;
699+ Some ( c)
700+ } else {
701+ None
702+ }
699703 }
700704 } else {
701705 None
702706 } ;
703707
704708 if let Some ( mut m_c) = post {
705- {
706- let mut current_child: tokio:: sync:: RwLockWriteGuard < ' _ , ChildType > =
707- current_child. write ( ) . await ;
708- let new_child = m_c. spawn ( ) . map_err ( IOError :: from) ?;
709- current_pid = new_child
710- . id ( )
711- . ok_or_else ( || anyhow:: anyhow!( "process failed, couldnt get pid" ) ) ?;
712- * current_child = ChildType :: ChildProcess ( new_child) ;
713- }
709+ let result = {
710+ {
711+ let mut current_child: tokio:: sync:: RwLockWriteGuard < ' _ , ChildType > =
712+ current_child. write ( ) . await ;
714713
715- send_process (
716- uuid,
717- current_pid,
718- ProcessPayloadType :: Modified ,
719- "running post hook" ,
720- )
721- . await ?;
714+ let new_child = m_c. spawn ( ) . map_err ( IOError :: from) ?;
715+
716+ current_pid = new_child
717+ . id ( )
718+ . ok_or_else ( || anyhow:: anyhow!( "process failed, couldnt get pid" ) ) ?;
719+
720+ * current_child = ChildType :: ChildProcess ( new_child) ;
721+ } ;
722+
723+ send_process (
724+ uuid,
725+ current_pid,
726+ ProcessPayloadType :: Modified ,
727+ "running post hook" ,
728+ )
729+ . await ?;
722730
723- loop {
724731 let value = current_child. write ( ) . await . try_wait ( ) ;
725- if let Some ( stat) = value? {
732+
733+ if let Ok ( Some ( stat) ) = value {
726734 exit_status = stat;
727- break ;
728735 }
729736
730- tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 10 ) ) . await ;
737+ Ok :: < ( ) , crate :: Error > ( ( ) )
738+ } ;
739+
740+ if let Err ( err) = result {
741+ tracing:: error!( "failed to run post hook: {err}" ) ;
742+ let _ = send_message ( format ! ( "failed to run post hook: {err}" ) . as_str ( ) ) . await ;
731743 }
732- }
744+ } ;
733745
734746 send_process (
735747 uuid,
0 commit comments