Fork me on GitHub
#clojure-uk
<
2020-03-26
>
wesley.hall01:03:26

@folcon So I just had a look through trying to fathom the lacinia subscriptions stuff because it was on my todo list anyway. One immediate answer is, "if you are not using lacinia-pedastal to serve your graph over the web, then you'll get subscriptions working only with a rather large headache". It looks like most of the real work is done in the lacinia-pedastal library and the parts of lacinia core that handle subscriptions are effectively written as internal APIs. They are not private as such, but are lower level than the execute function that acts as the primary public API for executing regular queries. The entry point for subscriptions, seems to be invoke-streamer inside the com.walmartlabs.lacinia.executors ns, but all of the helpful stuff that execute does, like parsing the query and injecting any variables is bypassed when you invoke at this level. Personally, I think they are desperately missing an execute-subscription top level API, and maybe I will mess around trying to do a PR for this. As it stands though, best thing to do would be to go through the lacinia code looking at how execute works. If you look at how execute prepares a call to execute-query (via execute-parsed-query), then it looks like you need to prepare the context object in basically the same way before invoking invoke-streamer. Though once you do this, you can simply pass your callback function and handle the pushing of any callback invocations down your websocket stream. If you are are using the lacinia-pedastal library, then as far as I can see it should just work, though you do need to "switch it on". This doesn't seem to be documented on the lacinia-pedastal readme (edit: apparently it is in the manual so you have probably seen this) but subscriptions are turned off by default and you need to pass a {:subscriptions true} option when you create the pedastal service map, the same way that {:graphiql true} is shown on the readme. This should start the server listening on /graphql-ws , which, at least according to the docs (I haven't tested it), should behave the same way as Apollo.

wesley.hall01:03:07

TLDR; Just implement polling 😉

folcon02:03:19

Well I’ve been digging into a not quite completed example that someone whipped up, it’s somewhat instructive? Hopefully it will give me enough of an idea of how things work that I can decide whether lacinia is worth jumping into pedestal for… Code is here -> https://github.com/Folcon/hn-clj-pedestal-re-frame, my current issue is not being sure how I can get session data, and for some reason my com.walmartlabs.lacinia.pedestal.subscriptions keep disconnecting, not that it appears to do anything… Re the session data, I’ve tried implementing this: https://raw.githubusercontent.com/transducer/lacinia-pedestal/bf1dba28011fe9f0ae6ab0f2a338dca73edbb5d0/docs/interceptors.rst but the interceptor never set’s the :lacinia-app-context, so I can’t even see if the session info is available to be passed on… I’ve got websockets working at the moment with sente, part of the reason for doing this was to allow the frontend more freedom to specify what it got back from the backend over sockets, so less long polling and more write my own version of graphql for websockets? 😞 Time for bed me thinks =)… I’ll pick this up tomorrow!

wesley.hall13:03:18

I see. Honestly I don't know too much about the client side problems. I am not super happy with the pedestal module for lacinia. I prefer to keep a bit of a closer control of my web tiers. I have a little bit of infrastructure that handles exposing lacinia over the web by only for queries and mutations, had not started looking at subscriptions yet. I might have a play with this. If I find anything useful i'll let you know.

wesley.hall13:03:54

There is, imho, some bad design in all this. It's weird to me that when you do a query lacinia does the main lifting, but when you do subscriptions, lacinia-pedestal does the same lifting.

folcon22:03:51

Thanks =)…

folcon22:03:12

Would be interested to know if you figure something out ;)…

dharrigan06:03:34

Good Morning!

dominicm07:03:27

We got yada hooked up with pedestal streams pretty easily. I think there's an example in edge. @folcon

dominicm07:03:46

The work in Lacinia pedestal is mostly to work around the fact there's no content negotiation, JSON generation or good async solution in pedestal. Iirc anyway.

yogidevbear08:03:33

Morning. How is everyone holding up? People with kids doing okay? People living alone staying in touch with other humans via video calls? And everyone in between?

thomas08:03:36

we are managing...

dharrigan08:03:55

Yeah, pretty much. I'm load balancing my kid with my wife during the day. But the latency can be very high given work responsibilities and nap times.

yogidevbear08:03:37

Yeah, we've got school work we're trying to help our son stay focused on. It feels like an immense task, especially when you throw work into the mix. I wonder how different schools are approaching their teaching strategies with the current lockdown situation.

dharrigan08:03:40

Our child is 3 years old (nearly), so having a "schedule" doesn't quite work (yet), but we have some things we do - like walk with daddy in the morning and afternoon. As for schools, no idea.

dharrigan08:03:15

(wife nap times, not kid nap times 🙂 )

thomas08:03:25

We try and go for a walk each lunch time.

yogidevbear08:03:29

We've been doing exercise classes via YouTube videos. Seems to work well

dharrigan08:03:00

PE with Joe 🙂

yogidevbear08:03:01

Yup, been doing that too 😂

jakob.durstberger08:03:06

I live on my own so I have to say it’s been pretty boring 1.5 weeks so far. 😕

yogidevbear08:03:45

Are you joining any video calls and chatting to people? There are also a few virtual Clojure meetups happening. Is like to try attend sole of those myself

yogidevbear08:03:38

It might even be worth starting a small zoom group or something for people to have some #watercooler time with others struggling with the isolation

jakob.durstberger08:03:43

Yeah, I’ve been chatting with my family and colleagues and it makes it bearable. I am just a big fan of going into the office for work and being around other people

jakob.durstberger08:03:35

We have similar things in place, we also have a 3pm tea time hangouts 🙂

yogidevbear08:03:18

Nice, that's really good to hear re the tea time hangouts :+1:

edward.hughes191109:03:23

Sounds like a Clojure Discord server is on the cards 😀

glfinn8309:03:41

I would love to be able to program, play VR and consume nothing but pizza and beer for a few weeks

glfinn8309:03:06

Instead I'm having to run after a 2yo

yogidevbear10:03:14

Good luck with the two year old. At least you can't say you're getting bored... Probably just exhausted 😉

guy08:03:49

Morning!

peterwestmacott09:03:30

things going... okay here. Luckily we have a garden to put the children in and the weather's been good so far. I imagine this is way harder for a lot of people than it is for me.

eamonn.sullivan09:03:06

It's only week two, but I'm still getting up at my normal hour, running my normal distance, showering, getting dressed in my normal clothes and then going to my "office" (the bedroom next to my own, where I've jury-rigged a stand-up desk with a laptop and external monitor). Let's see how long until I'm working in my bathrobe and slippers... My ears are getting sore from the constant usage of headphones for the videoconferences, though.

guy09:03:07

Honestly i think this is the best plan, try and stick to your usual routine and adapt it a bit. Well done 👍

yogidevbear09:03:31

Yes, totally agree. I read/ watched something a while back about having a routine (getting out of bed, making the bed, getting dressed ect) was really healthy and helpful for people when they were unable to work etc. I think the same applies for everyone being stuck at home now. Keep a routine going to keep you going kind of thing

seancorfield17:03:31

That might have been me banging on about having a well-defined WFH routine and delineating part of your living space as "the office" so you actually "commute" to your office and "commute" home when you're done working.

seancorfield17:03:04

Having a separate work computer and a home computer also helps (I have a tiny laptop for home stuff and a 27" desktop dedicated to work stuff).

seancorfield17:03:25

Unfortunately, this isn't feasible/practical for everyone 😞

yogidevbear17:03:38

Yeah, if memory serves me correctly, I think it was a TED talk I watched by someone that used to be in the military (possibly about how to deal with productively working from home), but my memory is a little hazy

yogidevbear17:03:10

Routine is definitely a good thing though. Otherwise the wheels can fall off 😂

yogidevbear10:03:53

I'm just curious how people that are getting food deliveries booked at all? > Number of users in queue ahead of you: 97524

dominicm10:03:52

I just shop

dominicm10:03:00

It's not too bad

dharrigan10:03:45

Don't people feel, given this WFH increase that there seems to be more "control/checking" from up on top? After all, if you're not welded to your keyboard/video conference for at least 12 hours a day, you must be slacking(!) off in your yimyangs watching youtube videos of kitty cats.

dharrigan10:03:58

Managers (I believe) don't like not seeing bums on seats...

rickmoynihan10:03:54

Not with us; but we’re a pretty relaxed company — who’ve been doing remote working for years. If anything maybe we’ve gone more the other way… people starting to work more varied hours; and say things like “taking a few hours off to look after the kids” — but then making it up later, so probably overall an increase in flexibility. Though we always allowed that stuff anyway; more people require it now I think.

ben.hammond10:03:13

being avalable on Slack/Email does not strongly correlate with being productiive

ben.hammond10:03:35

Slack is just another outlet for procrastination

ben.hammond10:03:44

/ create space for the subconscious to chew over your current problem as you care to describe it

ben.hammond10:03:57

um I mean that progress is often invisible, especially if it is design-heavy

ben.hammond10:03:27

the whole hammock-time/lotus shoots growing underneath the water thing

dharrigan10:03:05

our company is not used to everyone working from home

dharrigan10:03:12

so there is a bit more control going on

ben.hammond11:03:16

from a middle-manager's point of view they are periously close to being shown up as unnecessary so haranguing you is their best way to seem relevant perhaps probably

eamonn.sullivan11:03:38

Where I work, our team has been split between London and Glasgow for a long time. All meetings are remote-first, even if you were in the office, because no one likes to be the only remote person on the end of an intercom to a room full of people. So when we all had to go home, it wasn't that much of a difference. Where it hurts a bit is in pair programming. Every once in a while, you'd pair with someone in the same office and get a break from the headphones and screen sharing. Now we're on headphones all day, every day. But as far as management is concerned, they've gotten used to not seeing us and stuff still gets done. They're trained.

ben.hammond11:03:06

Glasgow AND London? Is that Previse?

eamonn.sullivan11:03:33

No, BBC. It's in my profile, I think.

eamonn.sullivan11:03:24

Our particular team, which looks after all digital publishing, is primarily based in those two cities.

dominicm11:03:25

My thoughts are that we need to let them spy, for a while at least. Give them the initial comfort.

dominicm11:03:59

That's pretty much the end of my plan. Maybe "time".

dominicm11:03:37

The world seems overall better if society is remote first. Commuting, flying, is reduced. More time to rest, play with kids, etc.

dominicm11:03:58

Even if middle management want bums in seats. They'll ease off with time.

mccraigmccraig11:03:51

i'm confident you are just holding back because you've seen what happens to all those evil geniuses who spill the beans too early 😉

dominicm11:03:02

I already used my quota of Austin Powers for the week, but you can guess :)

glfinn8313:03:11

I'm stuck in OO thinking, i'm not sure I'm thinking this correctly in a FP way. I have api.clj wfich holds this function:

(defn ping-services
  "Pings all relevant external services and returns a status map"
  []
  (log/debug "Pinging all external services")
  {:aggregator "DOWN"
   :baas "DOWN"
   :ml-service "DOWN"
   :database "DOWN"})
Now it hasn't been implemented yet, just returns a fixed map. In my head I'd create aggregator.clj, baas.clj, ml_service.clj and database.clj, each of them would have (amongst other things) a ping function which would know how to ping their service. Then for instance the value would be something like :database (database/ping) For some reason this does not feel right. I then started thinking about how I'd actually create tests for this (pins-services) function. In Java I'd just mock the Objects needed and inject them. I was told by one Clojurian that I could use a protocol and SPI Objects (?) for this instead, that is, pass in a function that does the http call (I could then have a function coming from database.clj that actually communicated with the database) and use a pass in a dummy function that returns "TRUE" in tests. But how would I do that? Or is this a good approach at all?

rickmoynihan13:03:41

A million ways to do it — but agreggating the results into a map is the trivial bit. I’d suggest the main place is to test the individual ping procedures… If each of those returned {:service-id "VALUE"} aggregating them is just a merge. Or they can return [:id value] and can be put (into {} service-results)… either way I’d decouple along those kind of lines.

rickmoynihan13:03:11

within each ping procedure, you can mock out http things or whatever

rickmoynihan13:03:49

or you could call ping-services like (ping-services [ping-service-a ping-service-b]) where each service is just a fn/procedure to do the pinging; and ping-services just orchestrates and collects results. This can be tested with a arbitrary thunks, e.g.

(ping-services [(constantly [:service-a "DOWN"]) (constantly [:service-b "UP"])])

rickmoynihan13:03:44

you can obviously bike shed the details — but would suggest something along those lines is a starting point

dominicm13:03:54

The important thing is to make this function be part of orchestration I think. Functions take it's result as a parameter, functions don't call it for you

glfinn8314:03:03

@rickmoynihan @dominicm Good pointers, thanks a million. @dominicm Can you elaborate on that?

dominicm14:03:10

(report ping-data) not (report) where report: (defn report [] (ping))

glfinn8314:03:43

ah ok, so you mean passing in the report function, rather than letting ping-services take nothing and call the methods. Ofc that makes testing much easier

dominicm14:03:50

I meant the report data, not the function.

dominicm14:03:04

I think most of the time passing functions to domain logic is not idiomatic

rickmoynihan16:03:54

Sorry I got pulled away before finishing everything — what @dominicm say’s is totally true btw. Though I was more imagining ping-services would orchestrate the execution of the procedures i.e. provide the strategy rather than report on them per se… At a basic level the distinction isn’t that important, but the orchestration is where the trickier aspects in this sort of thing happen; e.g. whether it’s acceptable for the requests themselves to be made sequentially; or whether they want to occur in parallel… then if parallel how you join the results back together; manage timeouts, different kinds of errors, retries whatever. Keeping those concerns separate from reporting then becomes important etc… it really depends on how far you want to go.

glfinn8316:03:02

The ping-services function is being called via http endpoint /health, so them taking some time does not matter really, it's really just something I might use to double check setup

glfinn8316:03:31

So the function is not that important really

conan17:03:10

Hi isolated peeps! I'm in the market for a clj/cljs formatter - we have emacs, cursive and calva in the team, and calva can't format files with namespaced keywords because of a bug in cljfmt. Does anyone know of an IDE-independent formatter?

dominicm19:03:51

Zprint is your best bet

dominicm19:03:03

It's canonical unlike cljfmt, so there's no arguments

dominicm19:03:25

I hate the output though. It aims for 80 chars per line.

mccraigmccraig09:03:42

i do like 80 chars per line... lets me have 3 column layout in emacs

dominicm09:03:53

No. Max is fine. But zprint aims for lines to be 80 chars.

dominicm09:03:03

So you end up with long lets, things like that.

alex.lynham20:03:08

is the bug in cljfmt intractable?