supervisor_loop Subroutine

private subroutine supervisor_loop(delay0, max0, exe0)

Run the supervisor loop, restarting the child on non-zero exit.

The supervisor will: - Execute the child command. - Exit if the child returns 0. - Otherwise wait delay0 seconds and restart, until max0 is reached.

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: delay0
integer, intent(in) :: max0
character(len=*), intent(in) :: exe0

Calls

proc~~supervisor_loop~~CallsGraph proc~supervisor_loop supervisor_loop proc~build_child_command build_child_command proc~supervisor_loop->proc~build_child_command proc~sleep_seconds sleep_seconds proc~supervisor_loop->proc~sleep_seconds proc~choose_self_exe choose_self_exe proc~build_child_command->proc~choose_self_exe proc~get_arg get_arg proc~build_child_command->proc~get_arg proc~quote_arg quote_arg proc~build_child_command->proc~quote_arg proc~starts_with~2 starts_with proc~build_child_command->proc~starts_with~2 proc~sleep_os sleep_os proc~sleep_seconds->proc~sleep_os proc~sleep_spin sleep_spin proc~sleep_seconds->proc~sleep_spin proc~choose_self_exe->proc~get_arg proc~is_windows_os is_windows_os proc~quote_arg->proc~is_windows_os get_os_type get_os_type proc~sleep_os->get_os_type interface~fpm_watch_sleep_seconds fpm_watch_sleep_seconds proc~sleep_os->interface~fpm_watch_sleep_seconds proc~is_windows_os->get_os_type

Called by

proc~~supervisor_loop~~CalledByGraph proc~supervisor_loop supervisor_loop proc~maybe_supervise maybe_supervise proc~maybe_supervise->proc~supervisor_loop

Source Code

   subroutine supervisor_loop(delay0, max0, exe0)
      real, intent(in) :: delay0
      integer, intent(in) :: max0
      character(len=*), intent(in) :: exe0

      character(len=:), allocatable :: child_cmd
      integer :: code, attempt
      real :: delay

      child_cmd = build_child_command(exe0)
      attempt = 0
      delay = max(0.0, delay0)

      do
         code = 0
         call execute_command_line(child_cmd, exitstat=code)

         if (code == 0) exit

         attempt = attempt + 1
         if (max0 > 0 .and. attempt >= max0) then
            write(error_unit,'(a)') "fpm-watch: child exited with nonzero status; restart limit reached"
            stop code
         end if

         write(error_unit,'(a,i0,a,i0,a,f0.2,a)') "fpm-watch: child crashed/aborted (exit=", code, "), restart #", attempt, " in ", delay, "s"
         call sleep_seconds(delay)
      end do

      stop 0
   end subroutine supervisor_loop