biff

kpassapk 2024-06-19T17:21:13.553719Z

Hi! Any help appreciated. I'm trying out the scheduling example:

:tasks [{:task (fn [ctx] (println "hello there"))
            :schedule (iterate #(biff/add-seconds % 60) (java.util.Date.))}]
I get
Execution error (ClassCastException) at com.biffweb.impl.misc/use-chime$fn (misc.clj:126).
class clojure.lang.Iterate cannot be cast to class clojure.lang.IFn (clojure.lang.Iterate and clojure.lang.IFn are in unnamed module of loader 'app')

2024-06-19T17:25:06.878069Z

Hey! You just need to wrap it in a function: :schedule (fn [] (iterate #(biff/add-seconds % 60) (java.util.Date.))). That way the use-chime component can get the schedule starting at the time the system starts up instead of at the time the namespace with your module is required.

kpassapk 2024-06-19T17:26:55.451559Z

Makes sense. I copied & pasted from here. Will correct + send PR if that's useful. https://github.com/jacobobryant/biff/blob/master/src/com/biffweb.clj#L976

2024-06-19T17:28:06.765879Z

ah yes that should be updated. I can go ahead and fix that.

2024-06-19T17:28:11.831729Z

thanks for the catch!

kpassapk 2024-06-19T17:33:20.889949Z

thumbsup_all

2024-06-19T17:35:18.276569Z

(Responding to your deleted message, maybe you figured it out already) In that case I wouldn't use scheduled tasks at all. Instead you can create a custom component:

(defn use-something [ctx]
  ;;; your code here
  ctx)

(def components
  [...
   biff/use-chime
   biff/use-beholder
   use-something])
do-something might be a better name than use-something; I just do use- as a convention.

๐Ÿ‘ 1
kpassapk 2024-06-19T17:48:54.495659Z

Yeah, i was trying to debug something with the module I'm working on and this was my last resort. I'll write it up in a separate thread.

kpassapk 2024-06-19T18:00:43.767069Z

Edits: for clarity I created a https://github.com/unifica-ai/pasaporte/tree/main for Biff + Keycloak. In the use-keycloak https://github.com/unifica-ai/pasaporte/blob/main/src/com/pasaporte/auth.clj#L165, I load the .well-known/openid-configuration from Keycloak. All works great on local. To share my project with non-Clojure devs, I added an uberjar build to the https://github.com/unifica-ai/pasaporte/blob/main/docker-compose.yml#L4 file - pretty standard stuff. When I launch the application from the container, though, I get a โ€œConnection refusedโ€ https://gist.github.com/kpassapk/73f557a7255e902281c6768043e82811. Looking at the debug output of clj-http, all looks good. If I call the same function in the /auth/config handler, all is good. During application startup = connection refused. I tried all sorts of things over the last 1/2 day like moving it to the background, doing it in a scheduled task that runs immediately (see last thread), but still no. I have diffed the debug output from clj-http and it's all the same. The call in the handler works, and the one in my application startup fails with connection refused. I realize this is likely nothing to do with Biff, but who knows. It goes against all my intuition. I'm going to forget about it for now, it's just too bad I can't share with the non-Clojure devs. Any ideas welcome, perhaps it's something obvious.

2024-06-19T19:15:46.120449Z

I think I see the problem actually! From your stacktrace I see it's the jwks-keys function that's failing, i.e. oidc-get-well-known-config must be returning successfully. And your /auth/config handler only calls the latter function, not jwks-keys. So maybe there's a bug there.

2024-06-19T19:18:08.844809Z

of course if it works locally, that makes things more interesting. But perhaps in the docker compose environment, the return value of oidc-get-well-know-config is different than it is locally for some reason?

2024-06-19T19:21:06.458549Z

in any case, I'd definitely add :debug true to the jwks-keys function and call that in the /auth/config endpoint to compare

kpassapk 2024-06-19T20:03:40.394979Z

OMG ๐Ÿ˜ฎ

kpassapk 2024-06-19T20:03:46.945949Z

You're right

kpassapk 2024-06-19T20:06:11.970749Z

Thank you so much! Thing about working alone is sometimes you go down the wrong path and all sense abandons you. It works on local because the well-known endpoint returns localhost. I forgot to change that to "keycloak". Also momentarily forgot there was a second http request there at all somehow.

2024-06-19T20:08:09.783479Z

haha great to hear! I know the feeling. There's a class of bugs where they're so hard to find because they're simple enough that they slip past your defenses... I spent 6 hours once fighting some problem that ultimately was caused because I was passing an Integer somewhere instead of an int or something like that

2024-06-19T23:53:08.505839Z

boom. BOOM, I say https://biffweb.com/p/indexes-prerelease/

๐Ÿ†’ 3
๐Ÿ‘Š 2
๐Ÿ‘Š๐Ÿผ 1
5
๐Ÿ™Œ 2
๐Ÿ™Œ๐Ÿผ 1
2024-06-19T23:53:43.500599Z

@taylor.jeremydavid @jarohen finally got something put together with the secondary-indices API!

๐Ÿ‘ 1
โ˜บ๏ธ 1
Thomas Moerman 2024-06-20T07:34:53.131019Z

Always a pleasure following your work on Biff.

โž• 3
๐Ÿ™Œ 1
๐Ÿ™Œ๐Ÿผ 1
fung 2024-06-19T00:44:14.745639Z

How to clean the jar created by uberjar? I have add exclusions to dops.edn,But thereโ€™s librocksdbjni so and DLL files in the jar:

{com.biffweb/biff                    {:git/url ""
                                             :git/sha "ada149e"
                                             :git/tag "v1.8.2"
                                             :exclusions [com.xtdb/xtdb-core
                                                          com.xtdb/xtdb-rocksdb
                                                          com.xtdb/xtdb-jdbc]}

2024-06-19T17:01:19.535669Z

I just created a new project, excluded the xtdb libs, created the uberjar, and the rocksdb files were successfully excluded from the uberjar. Perhaps run clj -Stree and double check that the xtdb libs aren't in there? I have the following in my deps.edn :

:deps {com.biffweb/biff                    {:git/url "", :git/sha "c50311e", :git/tag "v1.8.13"
                                             :exclusions [com.xtdb/xtdb-core
                                                          com.xtdb/xtdb-jdbc
                                                          com.xtdb/xtdb-rocksdb]}
        ;; Provides xtdb.api functions that com.biffweb depends on, all of which throw UnsupportedOperationException
        com.biffweb/xtdb-mock               {:git/url "", :git/sha "c50311e", :git/tag "v1.8.13"
                                             :deps/root "libs/xtdb-mock"}
Running clj -M:dev uberjar; jar tf target/jar/app.jar | grep rocksdb gives me an empty result with exit code 1. If I run the same command with the default deps.edn I get a bunch of results:
$ jar tf target/jar/app.jar  | grep rocksdb
librocksdbjni-osx-x86_64.jnilib
librocksdbjni-linux64.so
...

๐Ÿ‘ 1
fung 2024-06-20T01:23:01.785699Z

Oh, the missing xtdb-mock, everything is normal after itโ€™s added in the deps.edn. When I followed the instructions in โ€œhow to use Postgres with biffโ€, I noticed the xtdb-mock in step 7,but I thought itโ€™s not a necessary dependency so I didnโ€™t added it to my deps.edn.

2024-06-19T01:04:35.894929Z

hm, I would have expected that to work. Just to confirm, if you delete the uberjar and then generate it again, it still has the rocksdb files in it? if so I'll try reproducing this tomorrow.

fung 2024-06-19T01:07:48.563309Z

Yes, delete then regenerate, and rocksdb files still appear.

๐Ÿ‘ 1
2024-06-22T16:39:37.735579Z

interesting--adding xtdb-mock shouldn't prevent any rocksdb files from getting into the uberjar; it just makes it so that if you add the xtdb libs to your :exclusions, you won't get an exception when biff code tries to do (require 'xtdb.api) etc. e.g. when I tried running clj -M:dev uberjar without xtdb-mock, the uberjar doesn't even build; I just get an exception. but, as long as it's working now, I guess we're all good!