API for fetching children jobs in Workflow Worker
Closed this issue · 2 comments
Is your feature request related to a problem? Please describe.
We're using Oban Pro's workflow worker to fan-out and generate several large financial reports, and to fan-in results into another worker to consolidate the generated financial reports into a single ZIP file before emailing the results somewhere.
We're currently using the recorded jobs feature of the Pro worker to store filepaths/URLs to each generated report and wanted a way to fetch them all automatically.
Describe the Solution You'd Like
We're currently doing something like so:
def children(job) do
query =
from(x in Oban.Job,
where: x.worker != ^job.worker,
where: x.meta["workflow_id"] == ^job.meta["workflow_id"]
)
Repo.all(query)
end
def parse_result(job) do
job.meta["return"]
|> Base.decode64!(padding: false)
|> :erlang.binary_to_term()
end
I couldn't find an officially supported API for doing something like this, but it sounds pretty useful.
Describe Alternatives You've Considered
We could get away with not using recorded jobs and maybe just upload things to a centralised place and download them that way.
We're happy with the above solution (though we'll want to support options for specifying that jobs are actually completed, etc) but just wanted to throw the feature request out there.
Additional Context
N/A
That's already supported with all_workflow_jobs/2
and fetch_recorded/1
!
For example, to fetch all of a job's dependencies and then extract the recorded values:
job
|> all_workflow_jobs(only_deps: true)
|> Enum.map(&fetch_recorded/1)
# [{:ok, result}, {:ok, result}, {:ok, result}]
You can also get all upstream jobs or filter them by name.
That's already supported with
all_workflow_jobs/2
andfetch_recorded/1
!For example, to fetch all of a job's dependencies and then extract the recorded values:
job |> all_workflow_jobs(only_deps: true) |> Enum.map(&fetch_recorded/1) # [{:ok, result}, {:ok, result}, {:ok, result}]You can also get all upstream jobs or filter them by name.
I feel silly now... I don't know how I missed those 🤦♂️
Sorry for wasting your time! 💔