Created
March 18, 2025 06:19
-
-
Save kitallis/4e964138bfeff991cdb94e4b95b404f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns trillain.handler | |
| (:require [clojure.string :as string] | |
| [compojure.core :refer [defroutes GET]] | |
| [compojure.route :as route] | |
| [ring.middleware.defaults :refer [site-defaults wrap-defaults]])) | |
| (defonce store (atom {})) | |
| (defonce job-eta-in-sec 10000) | |
| (defn- job [] | |
| (Thread/sleep job-eta-in-sec) | |
| (rand-int 42)) | |
| (defn- result [id] | |
| (if-let [work (get @store id)] | |
| (deref work) | |
| (-> store | |
| (swap! assoc id (future (job))) | |
| (get id) | |
| (deref)))) | |
| (defn- call [id] | |
| {:status 200 :body (str (result id))}) | |
| (defroutes app-routes | |
| (GET "/call" [id] (call id)) | |
| (route/not-found "You have reached basically, nowhere.")) | |
| (def app (wrap-defaults app-routes site-defaults)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment