def monitor_workers
      setup_process_manager_signals
      logger.info('Starting workers monitoring code...')

      loop do
        logger.debug("Checking workers' health...")
        @worker_pools.values.each do |pool|
          break if shutdown?
          pool.check_workers
        end

        break if shutdown?
        logger.debug("Sleeping for #{@config['poll_period']} seconds...")
        sleep(@config['poll_period'])
      end

    ensure
      logger.info("Workers monitoring loop is finished, starting shutdown...")
      # Send out stop signals
      stop_workers(false)

      # Wait for all the workers to die
      unless wait_for_workers(@config['wait_period'])
        logger.info("Some workers are still alive after 10 seconds of waiting. Killing them...")
        stop_workers(true)
        wait_for_workers(5)
      end
    end
def monitor_workers
      setup_process_manager_signals
      logger.info('Starting workers monitoring code...')

      loop do
        logger.debug("Checking workers' health...")
        @worker_pools.values.each do |pool|
          break if shutdown?
          pool.check_workers
        end

        break if shutdown?
        logger.debug("Sleeping for #{@config['poll_period']} seconds...")
        sleep(@config['poll_period'])
      end

    ensure
      logger.info("Workers monitoring loop is finished, starting shutdown...")
      # Send out stop signals
      stop_workers(false)

      # Wait for all the workers to die
      unless wait_for_workers(@config['wait_period'])
        logger.info("Some workers are still alive after 10 seconds of waiting. Killing them...")
        stop_workers(true)
        wait_for_workers(5)
      end
    end
-----------------------------------------------------------------------------------------------