honeydew
honeydew copied to clipboard
API for accessing in_progress jobs
For my use case, before placing a new job in the queue, I want to check if I am not duplicating work. So I would need to check if a job with the same parameters is already in the queue or being processed.
Honeydew.filter/2 allows me to search for jobs is the queue, but I realized that there is no API for finding jobs in progress. I can dig out this information out of data returned by Honeydew.status/2
Honeydew.status(:my_queue)
|> Map.get(:workers)
|> Enum.reduce([], fn {_k, v}, acc -> if not is_nil(v), do: [elem(v, 0) | acc], else: acc end)
or straight from Mnesia, which I am using as a backend
:mnesia.activity(:async_dirty, fn -> :mnesia.foldl(fn wrapped_job_record, list -> [elem(wrapped_job_record, 2) | list] end, [], :"honeydew_:my_queue_in_progress") end)
but it is unstable because any change in the structure of the data can break my code, and this worries me.
I would appreciate having an official API for getting "in progress" jobs (in this sense the request is related to #96).
PS. I am thinking that perhaps the simplest solution would be just updating Honeydew.filter/2, so that its result includes "in progress" jobs.