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

Make before_reset/0 an explicit callback function #550

Merged
merged 3 commits into from
Oct 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update event guide to include behaviour implementation, and correct b…
…efore_reset/1 to before_reset/0
  • Loading branch information
DilaksunB committed Jan 23, 2024
commit 4d7e2739ed9da539f5d395e1fdf4f7189eb5c0b4
5 changes: 4 additions & 1 deletion guides/Events.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 33,7 @@ defmodule ExampleHandler do
application: ExampleApp,
name: "ExampleHandler"

@impl Commanded.Event.Handler
def handle(%AnEvent{..}, _metadata) do
# ... process the event
:ok
Expand Down Expand Up @@ -120,6 121,7 @@ defmodule ExampleHandler do
application: ExampleApp,
name: "ExampleHandler"

@impl Commanded.Event.Handler
def handle(event, metadata) do
IO.inspect(metadata)
# %{
Expand Down Expand Up @@ -199,7 201,7 @@ end
An event handler can be reset (using a mix task), it will restart the event store subscription from the configured
`start_from`. This allow an individual handler to be restart while the app is still running.

You can define a `before_reset/1` function that will be called before resetting the event handler.
You can implement the `before_reset/0` callback that will be called before resetting the event handler.

```elixir
defmodule ExampleHandler do
Expand All @@ -211,6 213,7 @@ defmodule ExampleHandler do

alias Commanded.Event.FailureContext

@impl Commanded.Event.Handler
def before_reset do
# Do something
:ok
Expand Down