mirror of
https://git.asonix.dog/asonix/background-jobs.git
synced 2024-11-28 23:11:02 +00:00
Queue as many jobs as we can on ping
This change isn't incredibly important, but in cases where more than one jobs server is running, and one happens to get a heavy amount of new job traffic while the others get very few, it is possible that we can end up with unprocessed jobs in the DB while not every worker is busy. This change exausts our worker queue on ping if there are jobs available
This commit is contained in:
parent
875eec57dd
commit
0a509e0271
1 changed files with 8 additions and 5 deletions
|
@ -173,11 +173,14 @@ where
|
|||
trace!("Checkdb");
|
||||
|
||||
for (queue, workers) in self.cache.iter_mut() {
|
||||
if let Some(request) = workers.pop_front() {
|
||||
if let Some(job) = self.storage.request_job(queue, request.worker_id)? {
|
||||
request.addr.do_send(ProcessJob::new(job));
|
||||
} else {
|
||||
workers.push_back(request);
|
||||
while !workers.is_empty() {
|
||||
if let Some(request) = workers.pop_front() {
|
||||
if let Some(job) = self.storage.request_job(queue, request.worker_id)? {
|
||||
request.addr.do_send(ProcessJob::new(job));
|
||||
} else {
|
||||
workers.push_back(request);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue