Hourglass.Worker.Supervisor (hourglass v0.1.0)

Copy Markdown View Source

DynamicSupervisor of per-task-queue Hourglass.Worker GenServers.

Bridge-handle lifecycle is managed inside Hourglass.Worker itself: init/1 calls BridgeHolder.register_worker/2, terminate/2 calls BridgeHolder.unregister_worker/1. This module is a thin wrapper that supports adding and removing Workers dynamically (e.g. one per Temporal task queue the application serves).

Summary

Functions

Returns a specification to start this module under a supervisor.

Start a Worker child for opts[:task_queue]. The Worker's init/1 registers a bridge handle via BridgeHolder and starts the inner poll-loop Supervisor.

Stop the Worker for task_queue. Looks the Worker pid up via WorkerRegistry, terminates its child entry under this DynSup (which runs Worker.terminate/2, calling BridgeHolder.unregister_worker/1 along the way). If the Worker isn't registered, defensively unregister the bridge handle anyway (idempotent) and return {:error, :not_found}.

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(init_arg)

@spec start_link(term()) :: Supervisor.on_start()

start_worker(opts)

@spec start_worker(keyword()) :: DynamicSupervisor.on_start_child()

Start a Worker child for opts[:task_queue]. The Worker's init/1 registers a bridge handle via BridgeHolder and starts the inner poll-loop Supervisor.

stop_worker(task_queue)

@spec stop_worker(String.t()) :: :ok | {:error, :not_found}

Stop the Worker for task_queue. Looks the Worker pid up via WorkerRegistry, terminates its child entry under this DynSup (which runs Worker.terminate/2, calling BridgeHolder.unregister_worker/1 along the way). If the Worker isn't registered, defensively unregister the bridge handle anyway (idempotent) and return {:error, :not_found}.