How do I list or count Oban jobs which are currently executing, but only in the same node my code is running?
I’ve tried running something like:
Repo.all(
from(job in Job,
where: job.worker == ^MyWorker,
where: job.state in ["executing"],
)
)
But that gives me all the executing jobs across all nodes, and I need to know which jobs are executing only on the current node.
Currently, our backend runs in a kubernetes cluster, and this is related to some graceful shutdown logic, so we need it to be node specific. We also have Oban Pro.
The value in there is something like {NODE_NAME , NODE_UUID}. Do you know how I can get both the NodeName and NodeUUID, so I can use it to search in the table? I’ve only found how to get the PID, not uuid of it.
always gives the correct result! Why would that be?
Does it happen that a Job has the “executing” state, but it does not appear in the exec_count gauge?
Edit:
I think I understand it. It’s due to a misunderstanding of what the job state means. A Job might currently have the “executing” state, but not be running, in fact, it can mean that the job will execute in the future, is this correct? Or it might just be my database being inconsistent.
That’s most likely what is happening. Jobs reported by exec_count have live processes running. It’s possible to have job records marked as executingin the database when the processes aren’t running anymore. Those are called orphaned jobs, and they typically happen during shutdown when jobs run longer than the queue shutdown period.