This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-17
Channels
- # bangalore-clj (2)
- # beginners (51)
- # boot (20)
- # cider (14)
- # clara (1)
- # cljs-dev (14)
- # cljsrn (50)
- # clojure (140)
- # clojure-dev (5)
- # clojure-france (1)
- # clojure-gamedev (3)
- # clojure-italy (4)
- # clojure-poland (3)
- # clojure-russia (8)
- # clojure-sg (1)
- # clojure-spec (64)
- # clojure-uk (51)
- # clojurescript (54)
- # core-typed (1)
- # data-science (2)
- # datomic (61)
- # docker (1)
- # emacs (6)
- # events (1)
- # graphql (1)
- # hoplon (14)
- # leiningen (8)
- # luminus (3)
- # mount (6)
- # off-topic (18)
- # om (17)
- # parinfer (34)
- # pedestal (47)
- # play-clj (1)
- # protorepl (1)
- # re-frame (56)
- # reagent (11)
- # ring-swagger (5)
- # rum (6)
- # sql (1)
- # uncomplicate (2)
- # vim (3)
- # yada (31)
@bradford I don't know much about servlets, but you can set <url-pattern>
in web.xml
to route requests to particular servlets. Is that what you were after? https://github.com/pedestal/pedestal/blob/master/guides/documentation/service-war-deployment.md#step-two-configure-your-servlets
Is it possible to get access to the log in a Vase :query
statement (e.g. to create a route like user-count-as-of
that takes an #inst
as a param)?
@danielcompton Hrm, close. We run as jetty .jars though.
@chris_johnson Do you mean the Datomic log?
@mtnygard I do - or some way to get an asOf
version of the database for a given :query
That's fine
I was just about to say "It doesn't have to be easy" hehe
A very early interceptor puts the current db value in there via something like (assoc-in ctx [:request :db] (d/db conn))
But you could add an interceptor of your own to update that key with whatever db value you want.
So something like (update-in ctx [:request :db] d/as-of (get-in ctx [:request :params :when]))
might do the job
That is precisely the information I needed - thank you!
@mgrbyte I can take a look if you're able to make a gist or paste the code in a private message.
(Context for interested parties: I am building some "dashboard" style endpoints off an existing Datomic db that eschews keeping timestamp attributes on entities in favor of being able to just to ask for the time slice you want)
I am also very interested in the mention I saw of someone working on a Lambda provider for Pedestal for this project - pull the app page out into S3, Vase service in Lambda... if I get something like that built I will certainly report back to the group. :)
@chris_johnson Paul deGrandis is working on that very thing. The last time I spoke to him, he said there was something subtle that had to be done with class loaders to get Lambda to be happy with Pedestal. I think his work is going to show up in Pedestal itself some time soon(-ish).
So here’s something I have trouble knowing what I did wrong with:
given this interceptor:
#vase/intercept {:name :my-awesome-api.v1/db-as-of
:entry (fn [ctx]
(let [db (-> ctx :request :db)
as-of (datomic.api/as-of db (get-in ctx [:request :params :when]))]
(update-in ctx [:request :db] as-of)))}
I get
ERROR i.p.http.impl.servlet-interceptor - {:msg "Dev interceptor caught an exception; Forwarding it as the response.", :line 313}
clojure.lang.ExceptionInfo: Interceptor Exception: Assert failed: (valid-interceptor? %)
at clojure.core$ex_info.invokeStatic(core.clj:4725)
Indeed, and the answer was right there in the stacktrace too, if only I had been able to look right at :entry
and :enter
and see that they were different. Brains: really good at lots of things! But not all the things.
Hmm, I’m getting errors when using clojure version 1.9.0-alpha15
and up with Pedestal version 0.5.2
. I’m not exactly sure why
There was a version of core.async that pulled in a library that used bad syntax in a refer-clojure clause
There's a newer core.async that depends on a newer version of that library that fixes the syntax
For people intrigued or horrified by my questions this morning, here is the (apparently, I still have no tests around this) working interceptor to take in a path-param
specifying a date and update your Vase route’s DB to be as-of
that time:
#vase/intercept {:name :your-awesome-api.v1/db-as-of
:doc "Takes a timestamp and updates the db for this request to be `as-of` that timestamp"
:enter (fn [ctx]
(update-in ctx [:request :db] (constantly (datomic.api/as-of
(get-in ctx [:request :db])
(clojure.instant/read-instant-date (get-in ctx [:request :path-params :when]))))))}
Usage then looks like
(assumes your route looks like some-query-route-as-of/:when
)