Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow uuid generator to be configurable #450

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

FrancisMurillo
Copy link

@FrancisMurillo FrancisMurillo commented Jul 3, 2021

Allow uuid generator to be configurable via Commanded.Application uuid_generator options. (#445)

One caveat is with dynamic apps. During Commanded.Middleware.before_dispatch, the command_uuid and correlation_id is empty which may break some client assumption. For compatibility, it is set after before_dispatch.

I do need some guidance on how to update the guide specially this new option and the ecosystem of adapters. Also since elixir_uuid is optional, the docs might have to specify that as well.

@yordis
Copy link
Contributor

yordis commented Aug 8, 2021

I would suggest using https://github.com/bitwalker/uniq and https://github.com/bitwalker/uniq_compat and try to remove elixir_uuid dependency altogether. And maybe we wouldn't need lib/commanded/uuid.ex as well.

Copy link
Collaborator

@Freyskeyd Freyskeyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello and thank's for this amazing PR !

I've made some suggestions but I'm also concern about the UUID module which seems to be unnecessary as pointed by @yordis

Maybe can we completely remove it as suggested?


@doc false
@spec uuid_generator(Commanded.Application.t(), boolean()) :: (() -> uuid) | nil
def uuid_generator(application, true) do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have call this method uuid_generator! and removing the last argument

Suggested change
def uuid_generator(application, true) do
def uuid_generator!(application) do

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, applied.

@@ -191,7 +191,8 @@ defmodule Commanded.Assertions.EventAssertions do
@doc false
def with_subscription(application, callback_fn, opts \\ [])
when is_function(callback_fn, 1) do
subscription_name = UUID.uuid4()
uuid_generator = Commanded.Application.uuid_generator(application, true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can maybe use only one line here? we don't need uuid_generator afterward

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Made it more inline


pipeline =
pipeline
|> Map.update!(:command_uuid, uuid_updater)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you could have use Map.put_new_lazy

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Map.put_new_lazy does not work on structs since the key is always present and will be a NOOP.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you right I forgot about the struct!

alias Commanded.Commands.Dispatcher
alias Commanded.Commands.Dispatcher.Payload

opts = Keyword.merge(@command_opts, opts)

application = Keyword.fetch!(opts, :application)
uuid_generator = Application.uuid_generator(application, false) || fn -> nil end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe uuid_generator should return an fn -> nil end instead of just nil ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also updated Application.uuid_generator! returning an a zero arity function

@FrancisMurillo FrancisMurillo force-pushed the uuid-generator branch 2 times, most recently from aa98be2 to cb38a0e Compare September 16, 2021 14:39
@FrancisMurillo
Copy link
Author

Removed Commanded.UUID in favor of uniq_compat.

@slashdotdash
Copy link
Member

I think it was preferable to remove the dependency on :elixir_uuid and implement the default UUID generator using the v4 format by copying the UUID implementation.

@FrancisMurillo
Copy link
Author

So should have I retained Commanded.UUID and remove uniq_compat?

@slashdotdash
Copy link
Member

So should have I retained Commanded.UUID and remove uniq_compat?

Yes, I think so as dropping the dependency removes the potential for version clashes.

@FrancisMurillo
Copy link
Author

Restored Commanded.UUID while applying the other comments

@edwardzhou
Copy link

There are two PRs for the same purpose. May I know which one is better to merge?
@slashdotdash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants