Fork me on GitHub
#clojure
<
2015-10-16
>
roberto02:10:58

I have a basic component question. Given the following Database component. When this is started, I would assume that the component has 2 more keys at the end, and that I can access them in stop. However, the only key I see is what I construct it with (in this case it is uri). I’m missing something basic here. Any guidance?

(defrecord Database [uri]
  component/Lifecycle
  (start [database]
    (let [{:keys [conn db]} (mg/connect-via-uri uri)]
      (info "CREATED CONN: " conn)
      (assoc database :conn conn :db db)))

  (stop [database]
    (let [conn (:conn database)]
      (info "KEYS IN COMPONENT: " (keys database))
      (mg/disconnect conn)
      (dissoc database :db :conn))))

(defn start-database
  [uri]
  (map->Database {:uri uri}))

bhagany02:10:20

@roberto: I would expect :db and :conn to be available in stop, assuming start has been called...

bhagany02:10:34

Are you using the return value from start? Or still using the original record?

roberto02:10:45

yeah, start was called, and :db and :conn are available anywhere I inject Database

bhagany02:10:48

(using the original record would cause the behavior you're describing)

roberto02:10:50

but it isn’t there inside stop

bhagany02:10:57

so, you're doing something like (component/stop (component/start (start-database …)))?

roberto02:10:59

well, if my assumption is correct, I’ll file an issue along with a sample app. I’m in 0.3.0 by the way

roberto02:10:09

yeah, I do the following:

roberto02:10:41

(def comp-app (create-server {:uri mongo-uri}))
(component/start comp-app)
(component/stop comp-app)

bhagany02:10:52

you're not using the return value from start

richiardiandrea02:10:00

yes that is the problem

bhagany02:10:33

you're welcome simple_smile

roberto02:10:35

that is what happens when you do too much OO

bhagany02:10:49

It took me a few weeks to get my head around it, I feel your pain

roberto02:10:17

sweet, everything is working now. Awesome. Thank you again.

bhagany02:10:31

excellent, good to hear

nowprovision04:10:35

Reading https://github.com/Prismatic/schema/wiki/Defining-New-Schema-Types-1.0 and experimenting in repl. In first paragraph it mentions "explain is used for human-readable representations of the schema" however (s/explain (schema.core.EqSchema. "test")) returns a list with symbol and "test" (eq "test").. so do they mean developer readable? Im looking for a good way to go from schema validation errors to a bullet point list of issues on the frontend of what needs correcting

nowprovision04:10:05

side question, any clojurians in bkk atm?

nowprovision06:10:14

I can't see why (def s2 (s/conditional string? #(> (.length %) 0))) wouldn't work

nowprovision06:10:27

granted I know I can use (s/pred seq) instead

nowprovision06:10:14

ignore was misreading..

wei07:10:28

how would I translate this snippet into Clojure:

new GoogleCredential.Builder()

jonas07:10:59

(GoogleCredential$Builder.) should work

wei07:10:14

I’m getting Unable to resolve classname: GoogleCredential$Builder with that, would I have to explicitly import Builder?

wei07:10:17

solved it. needed to (:import [com.google.api.client.googleapis.auth.oauth2 GoogleCredential$Builder])

nowprovision07:10:17

wei, are you planning to use more java googleapis kit, if its just the oauth2 part you can use clj-http and clj-jwt

nowprovision07:10:48

This is a sample of how to use clj-http and clj-jwt to do the oauth2 service acc handshake https://gist.github.com/nowprovision/b73e4f38fac13fcc1aab

wei08:10:32

@nowprovision: thanks for the sample. looks more straightforward than learning google’s specialized library. that said, it’s been done before: https://gist.github.com/terjesb/6783675

wei08:10:14

also looks like that example requests a new access token for each request. ideally you could use the same one until it expires

nowprovision08:10:22

its not to be used as is, just an example to get it working, deal with the idiosyncratic of google's oauth2

borkdude09:10:37

(rant "Clojure has made me unable to program Java. A colleague suggested the 'adapter pattern' as a workaround for a problem. This would result in an extra class for every domain class. That feels so illegal to me, I could never do that.")

mccraigmccraig09:10:22

@borkdude: maybe time for a new job if the job is forcing you to do things you no longer want to do ?

nowprovision09:10:38

@borkdude kotlin? the guy writing cursive clojure claims interops story is extremely good and integration performant and painless (due to not having to compile clojure.main)

borkdude09:10:38

@mccraigmccraig: @nowprovision If I was working in a 'product' company I would rewrite the entire application in Clojure. But since we are a services/consulting company, you always have to get the client paying for such a change. Now we have to deal with legacy with every yearly upgrade and RFC.

borkdude09:10:50

It's only temporary, but switching between these projects is kind of mind eh .... what is a decent word for it

agile_geek09:10:48

@borkdude: I used to be CTO of services/consulting company…and that is the reason that statement starts with ‘used to’.

agile_geek09:10:23

although currently I’m contracting so still doing whatever technology I’m told too!

emil0r12:10:07

does anyone know how to generate the code from a WSDL endpoint which appears to be using XML-RPC? complete noob at SOAP/WSDL etc

emil0r12:10:35

wsimport doesn't appear to be supporting that particular approach

mpenet14:10:53

et ca supporte que l anglais

mpenet14:10:58

(oups wrong chan)

nha15:10:54

@mpenet is there a French chan ? Never saw anyone in #C054B77K5

mpenet16:10:00

@nha no idea, my message was meant for another slack (work)

nha16:10:35

@mpenet: Ah I see 😛

edvorg17:10:44

Hi. How can I start many http-kit server apps and configure routing ports for each one?

edvorg17:10:52

Is there clojure only solution or should I use something like apache/nginx?

joelkuiper17:10:43

We’ve been using nginx as reverse proxy, works fine!

joelkuiper17:10:59

but you can just start multiple apps on different ports

joelkuiper17:10:33

even from within the Clojure app, since it’s basically function to start the HTTP kit handler on a port

dviramontes19:10:32

yo nice clj ppl; how do i serve a static directory other than "public" using ring ?

dviramontes19:10:37

every tutorial out there tells me to use (wrap-resource "/" "public) but i need to serve another directory

dviramontes19:10:53

@tyler: cool i'll check it out

tdantas21:10:56

hey mates ! using yesql how could I make one function private? and how could I redefine the function to handle exceptions ?

tdantas21:10:33

I just wrapped in another function with a try-catch. but I would like redefine with the exception handler

ddellacosta21:10:33

is there a schema type annotation for functions?

bensu21:10:31

@oliv: for private functions use defn- for private vars use (def ^{:private true} v ...)

tdantas21:10:18

yeah bensu, but using yesql we are using a macro

tdantas21:10:24

(defqueries ...)

bensu21:10:42

ahh desculpa, I'm out of context then

tdantas21:10:04

no worry mate

bensu21:10:10

dire might still help if the macro leaves a var behind

tdantas21:10:23

interesting ^^

bensu21:10:14

and for the private, you can try mixin with-meta with https://clojuredocs.org/clojure.core/alter-var-root

bensu21:10:13

if that works, don't forget to keep the original's var meta, otherwise you could lose something left by the macro

bensu21:10:32

(assoc old-meta :private true)

tdantas21:10:07

amazing bensu

ddellacosta21:10:22

bensu, that’s what I thought, but was wondering if folks have a way of validation functions

bensu21:10:27

you can always define your own by using a s/pred with fn?

ddellacosta21:10:33

oh, I suppose that works

bensu21:10:33

if you do, think about fn? vs ifn? since it might bite you

tom22:10:27

I'm running into a strange issue. In the terminal in multiple environments, lein ring uberjar will correctly compile a jar using ring options set in profiles.clj. But using the Jenkins lein plugin or just executing shell, lein ring uberjar complains that no handler is set for ring in project.clj. Anyone seen this?

ddellacosta22:10:49

tom, what is set for the jenkins user in profiles.clj or otherwise?

ddellacosta22:10:14

I’ve had to deal with vaguely similar issues recently, and had to set some env vars in my jenkins script/lein profiles.clj

tom22:10:41

Oh I see, I assumed it picked up from :uberjar profile?

ddellacosta22:10:49

hmm, I would too though actually

ddellacosta22:10:07

if you have an :uberjar profile in your project.clj

ddellacosta22:10:11

curious. 😕

ddellacosta22:10:29

oh, nevermind, not sure about that

ddellacosta22:10:44

not sure if the uberjar profile is passed through by whatever the ring plugin is doing

ddellacosta22:10:53

misread it and saw lein uberjar…

ddellacosta22:10:04

sorry @tom, I’m as puzzled as you

tom22:10:44

Hmmm.. I'll play around with it some more. I just wondered what jenkins could possibly be introducing into the mix--it's the only thing different.

nberger23:10:14

@tom: just to be sure... do you have :uberjar profile configuration in both profiles.clj and project.clj? If yes, that's the problem