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')
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.
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
ah yes that should be updated. I can go ahead and fix that.
thanks for the catch!
thumbsup_all
(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.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.
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.
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.
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?
in any case, I'd definitely add :debug true to the jwks-keys function and call that in the /auth/config endpoint to compare
OMG ๐ฎ
You're right
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.
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
boom. BOOM, I say https://biffweb.com/p/indexes-prerelease/
@taylor.jeremydavid @jarohen finally got something put together with the secondary-indices API!
Always a pleasure following your work on Biff.
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]} 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
...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.
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.
Yes, delete then regenerate, and rocksdb files still appear.
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!