faktory-rs icon indicating copy to clipboard operation
faktory-rs copied to clipboard

Make info command return ServerState struct

Open rustworthy opened this issue 10 months ago • 3 comments

Info command will now return a result with serde_json::Value which made a lot of sense during the period when the Faktory library was being actively developed and so the shape of the return type could change breakingly. The last time when that interface was updated was a couple of years ago and so we may want to introduce a dedicated type for it to make Client::info more ergonomic:

let server_state = client.info().await.unwrap(); // ServerState
let queues = &server_state.faktory.queues; // &HashMap<String, u64>

While currently - provided they know the keys - this will look like:

let server_state = client.info().await.unwrap(); // serde_json::Value
let queues = server_state.get("faktory").unwrap().get("queues").unwrap(); // &serde_json::Value

An example usage of Client::info can be found here

Since a breaking change is occurring due to switch to async, the Client::info can be updated to return ServerState.

rustworthy avatar Apr 10 '24 05:04 rustworthy

That seems reasonable! If we also annotate it with #[non_exhaustive], we'll even be able to expose more fields if they should be added.

jonhoo avatar Apr 27 '24 16:04 jonhoo

Related, see my recent Faktory PR which adds a typed structure for INFO.

mperham avatar Apr 27 '24 16:04 mperham

Ah, this is https://github.com/contribsys/faktory/pull/474?

Given we're doing a breaking change as part of #49 anyway, I think we should probably just remove .info entirely and add .current_info that returns a type matching the one you added here: https://github.com/contribsys/faktory/pull/474/files#diff-4bbbde2a77215c352f9e99f0f2764fb9fb09eaa9052433b58a474b33019f7486R9

jonhoo avatar Apr 28 '24 07:04 jonhoo

Ah, this is contribsys/faktory#474?

Given we're doing a breaking change as part of #49 anyway, I think we should probably just remove .info entirely and add .current_info that returns a type matching the one you added here: https://github.com/contribsys/faktory/pull/474/files#diff-4bbbde2a77215c352f9e99f0f2764fb9fb09eaa9052433b58a474b33019f7486R9

Addressed in #59

rustworthy avatar Apr 29 '24 03:04 rustworthy