You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: grid_scheduler.rb
    path of file: ./repos/kontena/server/app/services
    
    the code of the file until where you have to start completion: require_relative 'grid_service_deployer'
require_relative '../mutations/grid_services/deploy'
require_relative 'logging'

class GridScheduler
  include Logging
  include Workers

  attr_reader :grid

  # @param [Grid] grid
  def initialize(grid)
    @grid = grid
  end

  def check_service(service)
    if should_reschedule_service?(service)
      reschedule_service(service)
    end
  end

  # @param [GridService] service
  # @return [Boolean]
  def should_reschedule_service?(service)
    return f
    
  def all_instances_exist?(service)
    available_nodes = service.grid.host_nodes.connected.to_a
    return true if available_nodes.size == 0

    strategy = self.strategy(service.strategy)
    service_instances = service.grid_service_instances.includes(:host_node).to_a
    current_nodes = service_instances.map{ |c| c.host_node }.compact.uniq.sort
    offline_within_grace_period = current_nodes.select { |n|
      !n.connected? && n.last_seen_at && n.last_seen_at > strategy.host_grace_period.ago
    }
    available_nodes = (available_nodes + offline_within_grace_period).uniq

    service_deploy = GridServiceDeploy.new(grid_service: service)
    service_deployer = GridServiceDeployer.new(
      strategy, service_deploy, available_nodes
    )
    return false if service_deployer.instance_count != service_instances.map{ |c| c.host_node }.compact.size

    selected_nodes = service_deployer.selected_nodes.uniq.sort
    selected_nodes == current_nodes
  end