mule/runtime/foreman
The per-queue task supervisor — Elixir Oban’s Task.Supervisor foreman
(queue/supervisor.ex starts one per queue; producer.ex spawns every job
through it). gleam_otp has no task supervisor, so this is a
factory_supervisor whose template runs thunks: the template executes in
the factory supervisor’s process, so process.spawn links the job to the
supervisor — Task.Supervisor.async_nolink semantics once the producer
adds its own monitor. Children are Temporary: the supervisor never
restarts a job process — retries are the engine’s business.
Types
The opaque factory handle plus its pid — the pid is kept alongside because
supervisor:terminate_child/2 (pkill) needs it and it cannot be extracted
from the opaque Supervisor type.
pub type Foreman {
Foreman(
supervisor: factory_supervisor.Supervisor(fn() -> Nil, Nil),
pid: process.Pid,
)
}
Constructors
-
Foreman( supervisor: factory_supervisor.Supervisor(fn() -> Nil, Nil), pid: process.Pid, )
Values
pub fn release_task(task task: process.Pid) -> Nil
Let a start_gated_task task begin running.
pub fn start() -> Result(actor.Started(Foreman), actor.StartError)
pub fn start_gated_task(
foreman foreman: Foreman,
run run: fn() -> Nil,
) -> Result(process.Pid, actor.StartError)
Like start_task, but the task blocks until release_task — the
Task.async_nolink owner handshake. A monitored task must go through
this: monitor the returned pid, THEN release it, so a fast task can never
exit before the monitor exists (a completed job’s noproc DOWN would be
misread as a crash and re-acked).
pub fn start_task(
foreman foreman: Foreman,
run run: fn() -> Nil,
) -> Result(process.Pid, actor.StartError)
Run run in a fresh process linked to the foreman. The caller monitors
the returned pid itself (async_nolink: linked to the supervisor, only
monitored by the producer).
pub fn terminate_task(
foreman foreman: Foreman,
pid pid: process.Pid,
) -> Nil
Task.Supervisor.terminate_child/2: shut the task down through its
supervisor (an exit shutdown, not a brutal kill). A task that already
finished is ignored, like Elixir’s {:error, :not_found}.