elnewbee

elnewbee

Design elixir application in OTP terms.

Greetings, everyone! :grinning: When learning elixir, I faced up with the next task.
I have mongodb with stored entities that have id, created_at and type fields, count of records around ~ 500_000.
So, I need to create an elixir app that fetch this records in batches and pass them (one by one) by REST API interface to other application. Moreover, I need to trackdown progress of entity migration with possible restarts/retries. How I should design this app in OTP terms?
Looks like I need a supervisor with single genserver, that pool data from mongodb in smaller batches (about 100 or more), after that, genserver pushes records via REST API (using Task module), until every record successfully sent and after that proceed next batch, right?
And if I need restarts, when application is stopped or something other happened, should I save every step of batch processing to local db, like ID range of entities and state of batch process, for example progressing / failed / succeded?
And how add to genserver functionality to stop processing? Save genserver status to its state and change status from client code?
If processed entity is duplicated, for REST API it’s OK situation. How should I design this app? Please, share your opinion! Thanks for answers, in advice! :purple_heart:

Most Liked

dimitarvp

dimitarvp

Regular stuff: mix new your_app --sup (the CLI option is for it to have an application supervisor).

Not sure you need a GenServer to fetch stuff from Mongo and then send it somewhere else, you can likely use Oban’s free tier and store somewhere in your DB the progress of the sending operation (though not sure if Oban has a connector to Mongo; likely not). But if you really feel you should use a GenServer then yeah, nothing stopping you.

Since you hinted at state being important I’d say yes, these pieces of data should be persisted somewhere. What you proposed as an idea to store ranges can and should work.

There are good articles on how to make your own GenServer but TL;DR you can just send it a message to stop processing and then shutdown itself (if you want that too).


Your question is too broad IMO. Start off with something and start asking a bit narrower questions. :smiley: You will not get it right from the first time and that’s okay.

Where Next?

Popular in Questions Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
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
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
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
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

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
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
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
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

We're in Beta

About us Mission Statement