artem

artem

Commanded: how do you send a command to all of the aggregates?

Hi all

I am implementing a small SaaS with Commanded and one of the areas I am trying Commanded with is counting credits. Every month a free account is going to get some credits which are to be expired within a month if not used.

For tracking it I’ve got a CreditStore aggregate that has buckets of credits with attached expiration time. Adding/using credits is as simple as processing commands AddCredits/UseCredits, but expirations and adding more credits every month (or whatever plan’s timeframe chosen) are more difficult.

Sure I can check credits on demand or via explicit command. E.g. when somebody logs in, I could auto send CheckUpdateCredits and it should work. However, I’d like these monthly expirations/additions happen at roughly correct timing so that I could send notifications like “you’ve got more credits now, go use them” and also have ability to do nice admin reports on what’s the situation right now.

What would be the way to have every single aggregate in the system process some command regularly?

Exact timing is not important, so it’s fine if it happens within an hour or so from the ideal moment. The best I was able to invent is forcing every aggregate have projection with own id and closest expiration time, then some cron-like utility every X minutes to check who needs to be checked and then send lots of CheckUpdateCredits commands to these.

Is this how periodic checks of all aggregates are usually done? Or is these some other [easy] way to schedule processing of all aggregates in the system once in a while?

First Post!

ouven

ouven

Hi,

I solved a problem with expiration time of marketplace offers - in a commanded system - by combining Oban scheduled jobs and single commands for every aggregate.

So, whenever the property expiration time changes, I create a new Oban job and maybe delete the old one directly from the execute callback.

Where Next?

Popular in Questions Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
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
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
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
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
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement