 
 ;; FIXME: was to-timestamp redundant here and in store-report? others don't have it...
 
-(defn exec-deactivate-node [{:keys [id received payload]} start-time db]
+(defn exec-deactivate-node [{:keys [id received payload]} start-time db conn-status]
   (let [{:keys [certname producer_timestamp]} payload]
-    (jdbc/with-transacted-connection db
-      (when-not (scf-storage/certname-exists? certname)
-        (scf-storage/add-certname! certname))
-      (scf-storage/deactivate-node! certname producer_timestamp))
+    (jdbc/retry-with-monitored-connection
+     db conn-status :read-committed
+     (fn []
+       (when-not (scf-storage/certname-exists? certname)
+         (scf-storage/add-certname! certname))
+       (scf-storage/deactivate-node! certname producer_timestamp)))
     (log-command-processed-messsage id received start-time :deactivate-node certname)))
 
 ;; Report submission

       (update :payload #(s/validate nodes/configure-expiration-wireformat-schema %))
       (update-in [:payload :producer_timestamp] #(or % (now))))))

(defn exec-configure-expiration [{:keys [id received payload]} start-time db]
  (let [{:keys [certname producer_timestamp]} payload
        expire-facts? (get-in payload [:expire :facts])]
    (when-not (nil? expire-facts?)
      (jdbc/with-transacted-connection db
        (scf-storage/maybe-activate-node! certname producer_timestamp)
        (scf-storage/set-certname-facts-expiration certname expire-facts? producer_timestamp))
      (log-command-processed-messsage id received start-time
                                      :configure-expiration certname))))


                (seq package_inventory) (update :package_inventory distinct))))))

(defn exec-replace-facts
  [{:keys [payload id received] :as command} start-time db conn-status]
  (let [{:keys [certname producer_timestamp]} payload]
    (jdbc/retry-with-monitored-connection
     db conn-status :repeatable-read
     (fn []
       (scf-storage/maybe-activate-node! certname producer_timestamp)
       (scf-storage/replace-facts! payload)))
    (log-command-processed-messsage id received start-time :replace-facts certname)))

;; Node deactivation
