Oban on phoenix apps with scope contexts

Option 3:

# In worker module:
defp scope, do: Scope.for_worker("myworker")

# In perform function
list = Blog.list_posts(scope())

# In scope module
defstruct user: nil, worker: nil
def for_worker(worker) when is_binary(worker) do
  %__MODULE__{worker: worker}
end
def for_worker(nil), do: nil
def for_worker(_), do: nil

I find it useful to use a sort of “fake” scope which only includes a module name so I can trace the operations on the db using paper_trail for example. It also means I don’t need functions with and without scope which is dangerous IMO if you have permissions on your users.