Helpers for propagating audit context through background job args maps.
Context is explicitly passed via serializable maps and never stored in process state, ETS, or a process dictionary. This satisfies CTX-05 and keeps helpers testable as pure functions.
Usage in a worker
def perform(%{args: args}) do
with {:ok, actor_ref} <- Threadline.Job.actor_ref_from_args(args) do
opts = Threadline.Job.context_opts(args)
Threadline.record_action(:member_synced,
[actor: actor_ref, repo: MyApp.Repo] ++ opts
)
end
endEnqueue with context
Serialize actor_ref with Threadline.Semantics.ActorRef.to_map/1 under the
"actor_ref" key alongside other string-key fields your worker expects.
Compile-time coupling
This module references only plain maps — no compile-time dependency on any specific job runner package. Pass the args map your worker receives into these helpers.
Summary
Functions
Extracts an ActorRef from a job args map.
Builds record_action/2 keyword opts from job args.
Functions
Extracts an ActorRef from a job args map.
Looks for an "actor_ref" key containing a map serialized by
ActorRef.to_map/1.
Returns {:ok, %ActorRef{}} or {:error, reason}.
Builds record_action/2 keyword opts from job args.
Extracts :correlation_id and :job_id from the args map. Pass these opts
(merged with :actor and :repo) to Threadline.record_action/2.
Example
opts = Threadline.Job.context_opts(args)
Threadline.record_action(:event, [actor: actor_ref, repo: Repo] ++ opts)