I have the following scenario I want to solve with Oban:
A job will be created that will fetch a list of users
For that list, I want to chunk them and create a job for each job that will do send an email for the users.
This seems like a good use of workflows, basically I start my workflow with just one job:
Workflow.new()
|> Workflow.add(:chunk_investors, new_chunk_investors(buy_lists_ids, actor_id))
|> Oban.insert_all()
Now, inside the job, I will have the chunked lists and append jobs to the workflow, something like this:
@job [queue: :email]
def chunk_investors(buy_lists_ids, actor_id) do
lists = ...
{:ok, jobs} = Workflow.all_jobs(job)
lists
Enum.with_index()
Enum.reduce(Workflow.append(jobs), fn {list, index}, jobs ->
Workflow.add("send_email_#{index}", new_send_email(list, actor_id))
end)
|> Oban.insert_all()
:ok
end
I think this should probably work fine, the issue is that i don’t have the job
struct to call Workflow.all_jobs
when my job is decorated… Is there some way to retrieve it so this can work? If not, is there some other way to recover the workflow?