ouven

ouven

Commanded: how to use process managers

Hi all,

I am using commanded in a project for 3 years now. So first of all: Thanks to the commanded team!

Context:
I have an aggregate that represents something similar like a company unit, that I have to close down.
The company unit has other aggregates linked to it. In this particular case it is hardware, that needs to be unregistered und users, that need to be removed from this company unit (revoking their permissions).

Problem:
When I was implementing such cases in the past, I used simple event handlers. In this new story I wanted to have a closer look at process managers.

What I did not get is, how to start a process, so what is the first event to listen to and to start the process manager instance from?

Is it the CompanyUnitClosed event, that was emitted by the CompanyUnit aggregate after sending a CloseCompanyUnit command to it?

Or is it more like a CompanyUnitCloseProecssStarted event that I would need to directly add to the event stream?

How was it supposed to be used?
I hope someone can help me with this two approaches or even present a new one!

Cheers
Ruben

Most Liked

jerdew

jerdew

The most useful of answers: It depends.

The aggregates that are attached to the Company, if they receive commands from sources other than the Company aggregate then you could have a race condition where you told the Company to close, and the Process manager turns to another aggregate to shut it down, but cannot or should not because it’s in the middle of its own workflow – if that workflow ever tried to call a command back on the closed Company, you might have some problems, especially if the event was billable or otherwise very important.

Non exhaustive list of options:

  • You just close up children aggregates even if they’re in the middle of something because… it’s fine in your case
  • The PM could handle these errors (upon calling child aggregate it gets back an unexpected response, perhaps it could reopen the company, or something.) In the meantime the company is closed and acts/is projected that way, but attached aggregates may be busy dealing with their own commands/events.
  • You set the company in a ‘closing’ state (like you suggested with CompanyUnitCloseProecssStarted) where the PM would finalize the shutdown, send a ‘complete’ command to the Company and then itself shutdown on a CompanyUnitCloseProcessCompleted -type event. This helps minimize the possible events/commands that children aggregates might be orchestrating before the Company is marked as ‘closed’.

The asyncness of the event sourced process can require complex solutions, and you can refactor the commands/events/processes in several ways each with their own failure modes. The main question is what guarantees do you need? That should drive your implementation.

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New

We're in Beta

About us Mission Statement