              (sql-raw (str " repositories.git_url ="
                            " ANY(exs.accepted_repositories) "))])))
 
-(def ^:private trials-excutors-query-ordered
-  (-> trials-excutors-base-with-repo
+(defn ^:private trials-excutors-query-ordered []
+  (-> (trials-excutors-base-with-repo)
       (sql-order-by [:jobs.priority :desc]
                     [:jobs.created_at :asc]
                     [:tasks.priority :desc]

;##############################################################################

(defn next-trial-for-pull [tx executor]
  (->> (-> trials-excutors-query-ordered
           (sql-merge-where [:= :exs.id (:id executor)])
           (sql-merge-where [:= cider-ci.self/VERSION (:version executor)])
           (sql-limit 1) sql-format)


;#### debug ###################################################################
;(debug/wrap-with-log-debug #'next-trial-for-pull)
(logging-config/set-logger! :level :debug)
;(logging-config/set-logger! :level :info)
;(debug/debug-ns 'cider-ci.utils.http)
(debug/debug-ns *ns*)
