Implement a Poolboy worker
masterTo create a worker compatible with Poolboy, your module should implement the poolboy_worker behavior (or simply be a gen_server that accepts arguments in start_link/1).
Key requirements:
start_link(Args): Must accept a list of arguments used to initialize the worker (e.g., connection strings).init(Args): Should useprocess_flag(trap_exit, true)to ensure the worker can handle supervisor shutdowns gracefully.- Cleanup: Implement
terminate/2to close any resources (like database connections) held by the worker.
-module(my_worker).
-behaviour(gen_server).
-behaviour(poolboy_worker).
start_link(Args) ->
gen_server:start_link(?MODULE, Args, []).
init(Args) ->
process_flag(trap_exit, true),
% ... initialization logic ...
{ok, #state{...}}.
terminate(_Reason, #state{conn=Conn}) ->
% ... cleanup logic ...
ok.