greenz1
I am building an Elixir app for prod. It has a :observer.start layout as given below
My app’s flow is as follows.
Step 1: Workers under Elixir.AppName.MQTT.Supervisor receive some message.
Step 2: This message is sent to Elixir.AppName.Server
Step 3: Elixir.AppName.Server starts a worker dynamically under Elixir.AppName.on.Supervisor.
Step 4: The worker receives the message and acts accordingly
Let us call the worker, which is a GenServer, WORKER
My problem is that every time I have to perform some task in WORKERs I end up using send self(), message and having a corresponding handle_info in the WORKER.
I feel there is some issue with my current approach as I cannot utilize functions like GenServer.call or GenServer.cast
How should I remodel the application so that it makes use of other GenServer functions and callbacks?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #elixirconf-us
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming












Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kokolegorille
Without code it is hard to tell, but let me ask You why You would want to call or cast inside the GenServer?
It’s the API side that use those functions.
The server side has access to all private functions, and knows its state, in which case would You need to make intra server calls?
greenz1
I want to use call mainly because the worker is doing some CRUD operation in DB. I want to block the worker until the task is done.
By API side you mean something that a client(user or application) can use, right?
No intra-server calls have been planned.
Code structure is as follows
AppName.Server
AppName.on.Worker
kokolegorille
Maybe You can do like this?
BTW Why do You need to do this
instead of a simple function call?
greenz1
send self(), :some_taskis used so that the same task can be initialized by some other process.Yes, the module name was obfuscated thus the typo and AppName.on.Worker should be AppName.On.Worker
As the
some_task()cannot be called from within, so, from which process should I callAppName.On.Worker.some_task?