def _RemoveForemanRule(self):
    """Removes the foreman rule corresponding to this hunt."""
    if data_store.RelationalDBEnabled():
      data_store.REL_DB.RemoveForemanRule(hunt_id=self.session_id.Basename())
      return

    with aff4.FACTORY.Open(
        "aff4:/foreman", mode="rw", token=self.token) as foreman:
      aff4_rules = foreman.Get(foreman.Schema.RULES)
      aff4_rules = foreman.Schema.RULES(
          # Remove those rules which fire off this hunt id.
          [r for r in aff4_rules if r.hunt_id != self.session_id])
      foreman.Set(aff4_rules)