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

Shutdown idle aggregate processes. #57

Merged
merged 2 commits into from
Jun 2, 2017

Conversation

astery
Copy link
Contributor

@astery astery commented Jun 2, 2017

I propose implementing the following behavior to manage aggregate lifetime. The main intention was that aggregate life controller should be separated entity from domain logic.

defmodule ShopLifespan do
  @behaviour Commanded.Aggregates.AggregateLifespan

  # It specifies how long aggregate should live after processing command
  # @callback after_command(command) :: integer() | :infinity | :hibernate
  def after_command(%StartShopWork{}), do: 3600 * 1000 * 8
  def after_command(%StopShopWork{}), do: :hibernate
  def after_command(%CloseShop{}), do: 0
end

It should be specified in router:

defmodule CommandRouter do
  use Commanded.Commands.Router

  dispatch [
     StartShopWork,
     StopShopWork,
     CloseShop,
  ], to: MyAggregate, lifespan: MyAggregateLifespan, identity: :aggregate_id
end

@slashdotdash
Copy link
Member

@astery This looks like a great change, thanks for taking the time to implement #43.

@astery
Copy link
Contributor Author

astery commented Jun 2, 2017

I'm glad to hear that, thanks.

@slashdotdash slashdotdash merged commit ac7e973 into commanded:master Jun 2, 2017
@astery astery deleted the shutdown_idle_aggregates branch November 1, 2017 12:40
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

2 participants