We are working on a multi-tenancy implementation and would like to be able to set the dynamic repo automatically for the process, without having to tediously set it manually in process/1
Rationale:
A callback before_process/1 could be useful in a situation where the process/1 logic is still worker-specific, but the worker belongs to a group for which we would like to perform generic logic for some business reasons, e.g. modifying a meta, setting up dynamic repo, etc.
The callback could be run immediately before the process/1 is executed and would return the job itself.
The whole thing could work similarly to Oban.Pro.Worker.after_process/3
Example
With a callback like the one above, we could use functionality like the following:
defmodule MyCustomWorkerGroup do
defmacro __using__(_opts) do
quote do
@impl Oban.Pro.Worker
def before_process(%Oban.Job{} = _job) do
# do smth with the job or the worker process itself
end
end
end
end
defmodule MyWorker do
use Oban.Worker, queue: :default
use MyCustomWorkerGroup
@impl Oban.Pro.Worker
def process(job) do
# perform work
end
end
Feature
Add
Oban.Pro.Worker.before_process/1
callback.Problem to solve
We are working on a multi-tenancy implementation and would like to be able to set the dynamic repo automatically for the process, without having to tediously set it manually in
process/1
Rationale:
A callback
before_process/1
could be useful in a situation where theprocess/1
logic is still worker-specific, but the worker belongs to a group for which we would like to perform generic logic for some business reasons, e.g. modifying a meta, setting up dynamic repo, etc. The callback could be run immediately before theprocess/1
is executed and would return the job itself. The whole thing could work similarly toOban.Pro.Worker.after_process/3
Example
With a callback like the one above, we could use functionality like the following: