   "Returns true if the requested service-id has a healthy instance as per the state in the fallback-state."
   [fallback-state service-id]
   (-> fallback-state :healthy-service-ids (contains? service-id)))
+
+(defn retrieve-fallback-state-for
+  "Returns the fallback state for the provided service-ids."
+  [{:keys [available-service-ids healthy-service-ids]} service-ids]
+  {:available-service-ids (set/intersection available-service-ids service-ids)
+   :healthy-service-ids (set/intersection healthy-service-ids service-ids)})
 
 (defn missing-run-as-user?
   "Returns true if the exception is due to a missing run-as-user validation on the service description."


                    router-state-chan
                    (let [{:keys [all-available-service-ids service-id->healthy-instances]} message
                          current-state' (assoc current-state
                                           :available-service-ids all-available-service-ids
                                           :healthy-service-ids (-> service-id->healthy-instances keys set))]
                      (reset! fallback-state-atom current-state')
                      current-state')))
                (catch Exception e
                  (log/error e "error in fallback-maintainer")

            (meters/mark! (metrics/waiter-meter "core" "process-errors"))
            (utils/exception->response e request)))))))

(defn- log-service-changes
  "Logs changes to the tracker service ids."
  [new-service-ids old-service-ids qualifier]
  (when-let [old-ids-delta (seq (set/difference old-service-ids new-service-ids))]
    (log/info "no longer" qualifier "services:" old-ids-delta))
  (when-let [new-ids-delta (seq (set/difference new-service-ids old-service-ids))]
    (log/info "newly" qualifier "services:" new-ids-delta)))

(defn fallback-maintainer
  "Long running daemon process that listens for scheduler state updates and triggers changes in the
   fallback state. It also responds to queries for the fallback state."
