I think it depends on the type of worker. If the job being run is a deferred action a user is making that should be run in the scope of a user, putting the data necessary to reconstruct a user scope in the job is the right choice IMO. If the job is something that executes in a more privileged way, I actually define a new scope for that. For example, I have a scope defined for ingest and use that in function heads instead of a user scope. So you could imagine something like
defmodule MyApp.Accounts do
def create_user(%Accounts.Scope{admin: true} = scope, attrs) do
# ...
end
def create_user(%Ingest.Scope{} = scope, attrs) do
# ...
end
end
and again you’d store what you need in the job to construct such a scope. This way functions still expect some form of scope regardless.






















