Fork me on GitHub
#pedestal
<
2017-07-17
>
danielcompton00:07:05

@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

chris_johnson13:07:31

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)?

bradford15:07:31

@danielcompton Hrm, close. We run as jetty .jars though.

mtnygard15:07:32

@chris_johnson Do you mean the Datomic log?

chris_johnson15:07:03

@mtnygard I do - or some way to get an asOf version of the database for a given :query

mtnygard15:07:56

There's a way, with just a little bit of trickiness.

chris_johnson15:07:12

I was just about to say "It doesn't have to be easy" hehe

mtnygard15:07:19

The #vase/query action will use whatever database is present in the context map.

mtnygard15:07:12

A very early interceptor puts the current db value in there via something like (assoc-in ctx [:request :db] (d/db conn))

mtnygard15:07:36

But you could add an interceptor of your own to update that key with whatever db value you want.

mtnygard15:07:02

So something like (update-in ctx [:request :db] d/as-of (get-in ctx [:request :params :when])) might do the job

chris_johnson15:07:35

That is precisely the information I needed - thank you!

mgrbyte15:07:47

Is :vase/norms the right place to describe partitions and "seed-data" in a vase app?

mtnygard15:07:09

@mgrbyte Yep. That's exactly what I've done in another API.

mgrbyte15:07:37

thx @mtnygard I must be messing up the syntax 😛

mtnygard15:07:04

@mgrbyte I can take a look if you're able to make a gist or paste the code in a private message.

chris_johnson15:07:12

(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)

chris_johnson15:07:27

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. :)

mtnygard15:07:45

@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).

lxsameer16:07:52

pedestal's way of logging is so annoying

chris_johnson18:07:07

So here’s something I have trouble knowing what I did wrong with:

chris_johnson18:07:42

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)))}

chris_johnson18:07:03

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)

mtnygard18:07:13

One thing I see right away is :entry should be :enter

chris_johnson18:07:38

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.

ddeaguiar18:07:08

Hmm, I’m getting errors when using clojure version 1.9.0-alpha15and up with Pedestal version 0.5.2. I’m not exactly sure why

mtnygard18:07:20

what kind of errors?

mtnygard18:07:12

Believe it or not, I think I've seen that before.

ddeaguiar18:07:21

the clojure spec error eludes me…

mtnygard18:07:34

There was a version of core.async that pulled in a library that used bad syntax in a refer-clojure clause

mtnygard18:07:49

There's a newer core.async that depends on a newer version of that library that fixes the syntax

ddeaguiar18:07:08

could it be that Pedestal depends on the old version?

mtnygard18:07:20

Do you have a direct dependency on core.async?

mtnygard18:07:38

If not, then Pedestal 0.5.2 must depend on that older version.

ddeaguiar18:07:59

I can exclude core.async and depend on the latest version to see

ddeaguiar18:07:34

I was looking for an existing issue but I didn’t check the closed ones 😕

mtnygard18:07:56

I wish we had a state for issues that was "fixed but not released"

chris_johnson19:07:37

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

chris_johnson19:07:27

(assumes your route looks like some-query-route-as-of/:when)