Fork me on GitHub
#nbb
<
2022-07-14
>
johanmynhardt07:07:55

Oh hi. I'm new to nbb and wanted to try out the malli example last night but had some difficulties. Going back to the announcement Tweet it was... gone πŸ˜… I tried the initial example and then thought I'd try to use malli directly using the jar-workaround to use malli directly, but that's not working either and leaves me with :

----- Error --------------------------------------
Type:     TypeError
Message:  $APP.q is not a constructor
$APP.q is not a constructor
I can't figure out if I'm just being a noob, whether it's an actual issue or whether it's temporarily retracted.

borkdude07:07:49

Hey @U1M0BC7S7 - I noticed you liked that tweet and then I realized I should have taken it down. malli was for a brief moment part of nbb as an optional dependency, but I had troubles deploying both npm libs at the same time so I had to revert it unfortunately for now

johanmynhardt07:07:53

A right, I thought it might be something like that πŸ˜„ Thank you for confirming @U04V15CAJ I'll happily try again at a more opportune moment.

borkdude07:07:40

@U1M0BC7S7 #babashka now does work with malli though - do you need malli specifically for something Node.js related?

johanmynhardt07:07:41

I'm trying to convert an HTTP response checker from Clojure to nbb. I wrote it when I had no spec/malli knowledge and it runs in an always-on JVM process, so now I'm trying to convert it to a Serverless (AWS Lambda) model and also porting it to node/nbb for efficiency. I've done the footwork in #babashka but my skills for getting babashka to work in Lambda is not all there yet.

borkdude08:07:19

For bb there is blambda and holy lambda

johanmynhardt08:07:14

😯 Ooh, I'm going to have a look at those. Thank you!

johanmynhardt18:07:06

Yuuuuusss! partyparrot got blambda going. Thanks for the pointer!

borkdude18:07:18

Nice! @U054AT6KT will be happy to hear this

johanmynhardt19:07:12

What I've done a little differently is to create the resources via a CloudFormation template, which removes the need to keep track of the layer, role and policy ARNs while wiring it all up. Maybe not everyone's cup of tea, but it does make wiring up and tearing down the resources much easier πŸ˜… I need some πŸ’€ Thanks again for your help πŸ™

borkdude19:07:55

@U1M0BC7S7 Cool. It'd be cool if you shared your findings somewhere sometime and then we could link to it from https://github.com/babashka/babashka/wiki/AWS!

johanmynhardt07:07:08

@U04V15CAJ sure πŸ˜„ It's still a WIP, busy refactoring and clearing up things for a proposal: https://github.com/johanmynhardt/blambda/tree/cloudformation-poc/cfn In hindsight this looks like a lot more work, but once cleaned up I figure it would provide sleek layer + function management if abstracted away behind tasks. Need to get to actual work for today now.

jmglov08:07:56

@U1M0BC7S7 This is exactly what I had in mind. The lambda I'm working on uses Terraform instead of CloudFormation, but same basic idea. bb deploy was really only meant for getting started quickly. I’ll add TF and CF examples to the docs when I have time. πŸ™‚

❀️ 1
johanmynhardt20:07:50

@U054AT6KT I stumbled across your Dogfooding Blambda! : revenge of the pod people post πŸ˜ƒ I tried to zip up a pod layer's content along with the runtime, and the bootstrap script has the BABASHKA_PODS_DIR set. In addition, the environment definitely has it set to /opt/.babashka/pods. Somehow I still get the error from your post where it's looking in some home folder.

:cause /home/sbx_user1051/.babashka/pods/repository/org.babashka/aws/0.1.2/manifest.edn (No such file or directory)
From (System/getenv) I get "BABASHKA_PODS_DIR" "/opt/.babashka/pods". So now I'm not sure whether it's because I package it alongside the runtime or whether there's something else that I overlooked.

jmglov20:07:39

I seem to remember @U04V15CAJ saying that there was a bug with BABASHKA_PODS_DIR in some version of bb. Maybe try upgrading to the latest version, if it's not already?

borkdude20:07:09

yeah, you can use the latest master version from here: https://github.com/babashka/babashka-dev-builds

johanmynhardt16:07:58

πŸ™ Thank you, going to try that now.

johanmynhardt17:07:56

0.8.158-SNAPSHOT is πŸ‘Œ

babashka 2
jmglov08:07:13

@U1M0BC7S7 If you want to open a PR for Blambda to use this version, I’ll happily merge it. πŸ™‚

βž• 1
johanmynhardt08:07:16

OK, I'll have to add a change to support snapshot installs, the release URL is a bit different, I manually pulled and repackaged πŸ˜… Can only have a look again tonight.

jmglov08:07:53

No hurry at all, and this is definitely an β€œonly if you want to” sorta thing. πŸ˜‰

borkdude08:07:35

There will probably be another bb release in a week or two

❀️ 1
johanmynhardt08:07:57

πŸ˜„ I do want to. My OSS contributions are few and I'd like to change that.

πŸŽ‰ 1
genRaiy13:07:13

Marketing took over on the No compromise headline

❀️ 2
genRaiy13:07:13

Performance is always complicated to gauge

borkdude13:07:19

I thought I'd be the pedantic commenter before anyone else did it ;)

πŸ˜‚ 1
borkdude13:07:34

Really nice article, thanks for writing it (and publishing during your vacation)

1
genRaiy13:07:38

Where does it say sub millisecond startup time? I can't find it and don't remember writing that

borkdude13:07:34

> β€’ Blazingly fast starts: sub-millisecond. AWS provisioning latency is your only overhead, so no worse than any other language and better than many.

Joe Littlejohn14:07:17

πŸ™‹ The "no compromises" line was my fault Michiel. Writing pithy and intriguing blog subtitles is hard πŸ˜„

❀️ 1
borkdude14:07:23

No worries, just wanted to take away that expectation before people came complaining to me ;)

Joe Littlejohn14:07:05

"I had to compromise dammit!" πŸ”₯

borkdude14:07:43

It does make for a good headline on HN

nice 1
borkdude14:07:27

So, I tried to include schema and malli as optional dependencies but package them in a different npm package which you can optionally load. This sometimes worked and sometimes didn't. Npm publish failed for non-obvious reasons, as you can see here: https://github.com/babashka/nbb/commits/main?after=da04c12f88dacfbecaefda5b5e5bcb3fbd7a6ccb+69&amp;branch=main&amp;qualified_name=refs%2Fheads%2Fmain Because I had problems with this, I reverted it, but at some point I'd like to pick up on this idea again and at least support malli as a built-in but optional library. If anyone's got expertise with this, please chime in. Why do I want to push different modules to a different npm package? Because the baseline package should not become too big (just for sanity, but also the 3mb editing limit on AWS).

πŸ‘ 1
borkdude14:07:07

To be specific, the error that happened was:

npm ERR! code E404
npm ERR! 404 Not Found - PUT  - Not found
npm ERR! 404 
npm ERR! 404  '@babashka/[email protected]' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!
while @babashka/nbb-prismatic-schema was in fact already published

cldwalker14:07:02

If the artifact was published correctly but the npm registry is responding incorrectly, maybe https://www.npmjs.com/support can handle a bug report?

borkdude14:07:31

I mean, the library was published before but updating it to a newer version failed

borkdude14:07:00

An alternative to this would be to upload the artifacts to Github releases and let nbb pull them from there

borkdude14:07:57

Since they are standalone, it should not be more complicated than just downloading them to a predicable location

cldwalker14:07:59

Not sure what version it stopped working at. The above link to 0.5.112 does show as published on https://www.npmjs.com/package/@babashka/nbb-prismatic-schema

borkdude14:07:04

hmm, it seems the deploy did work then, but the client maybe responded badly?

borkdude14:07:50

however, 114 seems to be missing here for malli: https://www.npmjs.com/package/@babashka/nbb-metosin-malli

borkdude14:07:23

So due to this mess, I gave up on it

borkdude14:07:27

As you can see here, nbb + metosin malli succeeded here: https://app.circleci.com/pipelines/github/babashka/nbb/710/workflows/352ed3f3-3269-4c9d-a84b-258acfdea90f/jobs/634 but then at the end, schema failed

borkdude14:07:08

oh, it seems the version was wrong too:

npm ERR! 404  '@babashka/[email protected]' is not in the npm registry.

borkdude14:07:26

If someone can experiment with a setup like this, please let me know and I'll revisit

borkdude14:07:08

Hmm, maybe uploading the files to github releases first is good, and then I can retry the publish locally as well

borkdude16:07:36

@U1M0BC7S7 ^ see above for some context

βž• 1
vollcheck15:07:47

Hey, I have an issue with nbb execution: Let's say I have a function called put-graphql and internally, it loads a token from a file:

(defn put-graphql
  "Put a GraphQL document"
  [opts]
  (let [{access-token "access_token"} (load-token)]
    ...))
but if I call it like
(put-graphql {})
and run from terminal:
./script 
it returns:
----- Error --------------------------------------
Message:  da.call is not a function
----- Context ------------------------------------
100:
101: (defn put-graphql
102:   "Put a GraphQL document"
103:   [opts]
104:   (let [{access-token "access_token"} (load-token)
                                           ^--- da.call is not a function

da.call is not a function
Does anybody recognize what might be wrong? I was tweaking a little with p/let but have no idea where the problem comes from. Forgive me my lack of JS knowledge

borkdude15:07:51

Without any more context, I don't know what's wrong. What does load-token look like?

vollcheck16:07:24

like this:

(def load-token
  (let [token (-> os
                  .homedir
                  (str "/access-token.json")
                  fs/readFileSync
                  js/JSON.parse
                  (js->clj :keywordize-keys true)
                  :access_token)]
    (if token
      token
      (prn "Please get a new access-token to proceed"))))

borkdude16:07:44

ah, did you mean (defn [] load-token) perhaps?

borkdude16:07:56

else you shouldn't call it as a function

vollcheck16:07:27

uhh, yes... thanks

❀️ 1
vollcheck09:07:07

hey, I have similar issue with a.replace is not a function. Consider following snippet:

(cond-> (fs/readFileSync "resources.edn")
  :always (clojure.string/replace "{{base-uri}}" ""))
This time clojure.string/replace is a function, right?

borkdude09:07:30

you need to first call str on the result of readFileSync since that returns a buffer, unless you give a file encoding like "utf-8" to it

borkdude10:07:00

(fs/readFileSync "resources.edn" "utf-8")

vollcheck10:07:55

yes, it works, thank you! clojure-spin

borkdude10:07:45

I have made this mistake myself often too ;)