I'm still pretty new to OTP, and I'm embarking on creating my first real OTP application.
I'm probably conflating concepts here, but I think I want a Supervisor that behaves as a GenServer too. Correct me if I'm wrong, or suggest how to implement it if I'm right? Here's my situation.
Similar to the example in Programming Elixir, I have a supervisor tree:

The worker can receive commands to perform stateful work; the stash allows the worker to be restarted with its previous state on error. I want the entire tree above to behave as a single unit consumable through other applications, for example, the entire tree should be treated as a worker in a pool.
So the pool could spin up 5 of these trees, and if any component fails aside from the main supervisor it will be restarted properly. If the main supervisor fails the pool will start a new one.
When the pool receives work, it seems like it should send it directly to my main supervisor, since it shouldn't be aware of the unit's internal infrastructure. So each supervisor should also be a genserver that passes work down to its children until it hits the actual worker, right?
I also want is to be able to kill the worker if it takes too long.
This post on stackoverflow suggests doing this by having a parent start a :timer on a handle_call, and terminate the worker if the :timer returns first. In my tree this suggests the subsupervisor should have a handle_call, further reinforcing the idea that it should also be a genserver.
Is this the right way to do this? Is there a concept I'm missing? How does one properly rig up a supervisor as a genserver too? Is the following valid OTP?
defmodule My.Supervisor do
use Supervisor.Behaviour
use GenServer.Behaviour
def start_link(configuration) do
:supervisor.start_link(__MODULE__, configuration)
end
def init(configuration) do
children = [
worker(My.Worker, configuration, shutdown: :brutal_kill)
]
supervise(children, strategy: :one_for_one)
end
def handle_call({ :work, unit_of_work }, _from, configuration) do
# Somehow delegate to worker, run timer, etc?
{ :reply, result, configuration }
end
end
At a glance it seems strange because
a) There's no :genserver.start_link call
b) I have no idea if supervise returns the expected { :ok, starting_state } in init necessary for a genserver to be started
Please advise!