Skip to content

Commit

Permalink
Merge branch 'master' into initialize-with-handler-state
Browse files Browse the repository at this point in the history
  • Loading branch information
dvic committed Sep 19, 2024
2 parents cd95e43 + 1c247b1 commit 9da4bcf
Show file tree
Hide file tree
Showing 47 changed files with 806 additions and 381 deletions.
2 changes: 0 additions & 2 deletions .github/FUNDING.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ on: [push, pull_request]

env:
MIX_ENV: test

jobs:
build:
name: Build and test
runs-on: ubuntu-latest
strategy:
matrix:
otp: ['24.3', '25.0']
elixir: ['1.14.0']
otp: ['25.3']
elixir: ['1.15.7']

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.14.0-otp-25
erlang 25.0.4
elixir 1.15.7-otp-25
erlang 25.3.2.8
9 changes: 0 additions & 9 deletions BACKERS.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
# Sponsors & Backers

Commanded and EventStore are MIT-licensed open source projects. Ongoing development is only made possible thanks to the following awesome sponsors and backers.

You can join them and contribute to Commanded's future development.

* [Become a sponsor on GitHub](https://github.com/sponsors/slashdotdash)
* [Become a backer or sponsor on OpenCollective](https://opencollective.com/commanded).

---

## Sponsors via GitHub

Thank you to all our sponsors! 🙏
Expand Down
21 changes: 18 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
# Changelog

## Next release
## v1.4.3

- Record aggregate state while processing `Commanded.Aggregate.Multi` ([#507](https://github.com/commanded/commanded/pull/507)).
### Enhancements

- Use `Logger.warning` to fix deprecation warnings ([#542](https://github.com/commanded/commanded/pull/542)).
- Add typespec to `CompositeRouter.dispatch/2` function ([#536](https://github.com/commanded/commanded/pull/536)).
- Support `opts` in `Commanded.EventStore.append_to_stream` function ([#528](https://github.com/commanded/commanded/pull/528)).
- Process manager metadata access ([#514](https://github.com/commanded/commanded/pull/514)).

### Bug fixes

- Correct parameter type in `ProcessManager.after_command/1` callback function ([#533](https://github.com/commanded/commanded/pull/533)).

## v1.4.2

- Record aggregate state while processing `Commanded.Aggregate.Multi` ([#507](https://github.com/commanded/commanded/pull/507)).
- Properly handle EXIT signal in event handler ([#512](https://github.com/commanded/commanded/pull/512)).
- Separate logging a process managers error ([#513](https://github.com/commanded/commanded/pull/513)).

## v1.4.1

Expand All @@ -12,7 +27,7 @@

### Bug fixes

- Remove duplicate apply function call when receiving missed events published to an aggregate's event stream ([364c877](https://github.com/commanded/commanded/commit/364c877e8f30a18d90544676fb58b94132d50720)).
- Remove duplicate apply function call when receiving missed events published to an aggregate's event stream ([364c877](https://github.com/commanded/commanded/commit/364c877e8f30a18d90544676fb58b94132d50720)).
- Fix typespec typo in Commanded.Application ([#503](https://github.com/commanded/commanded/pull/503)).

## v1.4.0
Expand Down
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,14 @@ You can use Commanded with one of the following event stores for persistence:

Please refer to the [CHANGELOG](CHANGELOG.md) for features, bug fixes, and any upgrade advice included for each release.

Requires Erlang/OTP v21.0 and Elixir v1.9 or later.
Requires Erlang/OTP v21.0 and Elixir v1.11 or later.

---

### Supporting Commanded

You can help support Commanded by helping to fund its ongoing development, new features, and releases.
#### Sponsors

- [Become a GitHub sponsor](https://github.com/sponsors/slashdotdash)
- [View sponsors & backers](BACKERS.md)

#### Sponsors

[![Alembic](https://user-images.githubusercontent.com/3167/177830256-26a74e82-60ff-4c20-bd84-64ee7c12512c.svg "Alembic")](https://alembic.com.au/)

---
Expand Down Expand Up @@ -149,6 +144,7 @@ Commanded exists thanks to the following people who have contributed.
- [David Carlin](https://github.com/davich)
- [Damir Vandic](https://github.com/dvic)
- [Danni Friedland](https://github.com/BlueHotDog)
- [Dilaksun Bavarajan](https://github.com/DilaksunB)
- [Ernesto](https://github.com/lex-mala)
- [Fernando Mendes](https://github.com/justmendes)
- [Florian Ebeling](https://github.com/febeling)
Expand Down Expand Up @@ -176,13 +172,12 @@ Commanded exists thanks to the following people who have contributed.
- [Raphaël Lustin](https://github.com/rlustin)
- [Štefan Ľupták](https://github.com/EskiMag)
- [Tobiasz Małecki](https://github.com/amatalai)
- [Vladimir Drobyshevskiy](https://github.com/vheathen)
- [Willy Wombat](https://github.com/octowombat)
- [Yordis Prieto](https://github.com/yordis)
- [Yuri de Figueiredo](https://github.com/y86)
- [Zven](https://github.com/zven21)

## Need help?

Please [open an issue](https://github.com/commanded/commanded/issues) if you encounter a problem, or need assistance. You can also seek help in the [Gitter chat room](https://gitter.im/commanded/Lobby) for Commanded.

For commercial support, and consultancy, please contact [Ben Smith](mailto:[email protected]).
Please [open an issue](https://github.com/commanded/commanded/issues) if you encounter a problem, or need assistance. You can also seek help in the #commanded channel in the [official Elixir Slack](https://elixir-slackin.herokuapp.com/).
3 changes: 2 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import Config
alias Commanded.EventStore.Adapters.InMemory
alias Commanded.Serialization.JsonSerializer

config :logger, level: :debug
config :logger, :console, level: :debug, format: "[$level] $message\n"

config :ex_unit,
assert_receive_timeout: 1_000,
capture_log: true,
capture_log: [level: :debug],
exclude: [:distributed]

config :commanded,
Expand Down
5 changes: 3 additions & 2 deletions lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule Commanded.Application do

alias Commanded.Aggregates.Aggregate
alias Commanded.Application.Config
alias Commanded.Commands.Router

telemetry_event(%{
event: [:commanded, :application, :dispatch, :start],
Expand Down Expand Up @@ -286,7 +287,7 @@ defmodule Commanded.Application do
`Commanded.Commands.Router` and included in the application.
"""
@callback dispatch(command :: struct()) :: Commanded.Commands.Router.dispatch_resp()
@callback dispatch(command :: struct()) :: Router.dispatch_resp()

@doc """
Dispatch a registered command.
Expand Down Expand Up @@ -366,7 +367,7 @@ defmodule Commanded.Application do
@callback dispatch(
command :: struct(),
timeout_or_opts :: non_neg_integer() | :infinity | Keyword.t()
) :: Commanded.Commands.Router.dispatch_resp()
) :: Router.dispatch_resp()

@doc false
def dispatch(application, command, opts \\ [])
Expand Down
4 changes: 2 additions & 2 deletions lib/commanded/aggregates/aggregate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ defmodule Commanded.Aggregates.Aggregate do
timeout

invalid ->
Logger.warn(
Logger.warning(
"Invalid timeout for aggregate lifespan " <>
inspect(lifespan) <>
", expected a non-negative integer, `:infinity`, `:hibernate`, `:stop`, or `{:stop, reason}` but got: " <>
Expand Down Expand Up @@ -594,7 +594,7 @@ defmodule Commanded.Aggregates.Aggregate do
%Aggregate{state | snapshotting: snapshotting}

{:error, error} ->
Logger.warn(describe(state) <> " snapshot failed due to: " <> inspect(error))
Logger.warning(describe(state) <> " snapshot failed due to: " <> inspect(error))

state
end
Expand Down
2 changes: 1 addition & 1 deletion lib/commanded/aggregates/default_lifespan.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule Commanded.Aggregates.DefaultLifespan do
"""
@impl AggregateLifespan
def after_error(error) do
if Exception.exception?(error) do
if Kernel.is_exception(error) do
{:stop, error}
else
:infinity
Expand Down
13 changes: 9 additions & 4 deletions lib/commanded/commands/composite_router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ defmodule Commanded.Commands.CompositeRouter do
A composite router can include composite routers.
"""

alias Commanded.Commands.Router

defmacro __using__(opts) do
quote do
require Logger
Expand Down Expand Up @@ -91,18 +93,21 @@ defmodule Commanded.Commands.CompositeRouter do
Enum.map(@registered_commands, fn {command_module, _router} -> command_module end)
end

@doc false
@doc """
Dispatch a registered command.
"""
@spec dispatch(
command :: struct(),
timeout_or_opts :: non_neg_integer() | :infinity | Keyword.t()
) :: Router.dispatch_resp()
def dispatch(command, opts \\ [])

@doc false
def dispatch(command, :infinity),
do: do_dispatch(command, timeout: :infinity)

@doc false
def dispatch(command, timeout) when is_integer(timeout),
do: do_dispatch(command, timeout: timeout)

@doc false
def dispatch(command, opts),
do: do_dispatch(command, opts)

Expand Down
17 changes: 7 additions & 10 deletions lib/commanded/commands/dispatcher.ex
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
defmodule Commanded.Commands.Dispatcher do
@moduledoc false

require Logger

alias Commanded.Aggregates.Aggregate
alias Commanded.Aggregates.ExecutionContext
alias Commanded.Commands.Router
alias Commanded.Middleware.Pipeline
alias Commanded.Telemetry

require Logger

defmodule Payload do
@moduledoc false

@type t :: %Payload{}

defstruct [
:application,
:command,
Expand All @@ -35,13 +37,8 @@ defmodule Commanded.Commands.Dispatcher do

# Dispatch the given command to the handler module for the aggregate as
# identified.
@spec dispatch(payload :: struct) ::
:ok
| {:ok, aggregate_state :: struct}
| {:ok, aggregate_version :: non_neg_integer()}
| {:ok, events :: list(struct)}
| {:ok, Commanded.Commands.ExecutionResult.t()}
| {:error, error :: term}
@spec dispatch(payload :: Payload.t()) ::
Router.dispatch_resp() | {:ok, events :: list(struct())}
def dispatch(%Payload{} = payload) do
pipeline = to_pipeline(payload)
telemetry_metadata = telemetry_metadata(pipeline, payload)
Expand Down
13 changes: 7 additions & 6 deletions lib/commanded/commands/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ defmodule Commanded.Commands.Router do
"""

alias Commanded.Commands.Router
alias Commanded.Aggregates.DefaultLifespan
alias Commanded.Commands.{ExecutionResult, Router}
alias Commanded.UUID

defmacro __using__(opts) do
Expand All @@ -216,7 +217,7 @@ defmodule Commanded.Commands.Router do
import unquote(__MODULE__)

@before_compile unquote(__MODULE__)
@behaviour Commanded.Commands.Router
@behaviour Router

Module.register_attribute(__MODULE__, :registered_commands, accumulate: true)
Module.register_attribute(__MODULE__, :registered_middleware, accumulate: true)
Expand All @@ -227,7 +228,7 @@ defmodule Commanded.Commands.Router do
consistency: Router.get_opt(unquote(opts), :default_consistency, :eventual),
returning: Router.get_default_dispatch_return(unquote(opts)),
timeout: 5_000,
lifespan: Commanded.Aggregates.DefaultLifespan,
lifespan: DefaultLifespan,
metadata: %{},
retry_attempts: 10
]
Expand Down Expand Up @@ -369,7 +370,7 @@ defmodule Commanded.Commands.Router do
:ok
| {:ok, aggregate_state :: struct()}
| {:ok, aggregate_version :: non_neg_integer()}
| {:ok, execution_result :: Commanded.Commands.ExecutionResult.t()}
| {:ok, execution_result :: ExecutionResult.t()}
| {:error, :unregistered_command}
| {:error, :consistency_timeout}
| {:error, reason :: term()}
Expand All @@ -386,7 +387,7 @@ defmodule Commanded.Commands.Router do
:ok = BankRouter.dispatch(command)
"""
@callback dispatch(command :: struct()) :: dispatch_resp
@callback dispatch(command :: struct()) :: dispatch_resp()

@doc """
Dispatch the given command to the registered handler providing a timeout.
Expand Down Expand Up @@ -462,7 +463,7 @@ defmodule Commanded.Commands.Router do
@callback dispatch(
command :: struct(),
timeout_or_opts :: non_neg_integer() | :infinity | Keyword.t()
) :: dispatch_resp
) :: dispatch_resp()

defmacro __before_compile__(_env) do
quote generated: true do
Expand Down
Loading

0 comments on commit 9da4bcf

Please sign in to comment.