diff --git a/mutalyzer/Scheduler.py b/mutalyzer/Scheduler.py index e4816720ff8653fca43f60232114ed038240f907..f82671a709cc553172c4e2082220978049b47c0b 100644 --- a/mutalyzer/Scheduler.py +++ b/mutalyzer/Scheduler.py @@ -364,9 +364,18 @@ Mutalyzer batch scheduler""" % url) refers to the reason of alteration / skip. """ while not self.stopped(): - batch_jobs = BatchJob.query - - if batch_jobs.count() == 0: + # Group batch jobs by email address and retrieve the oldest for + # each address. This improves fairness when certain users have + # many jobs. + # Note that batch jobs submitted via the webservices all have the + # same email address, so they are effectively throttled as if all + # from the same user. Adapting the webservices to also allow + # setting an email address is future work. + batch_jobs = BatchJob.query.filter(BatchJob.id.in_( + session.query(func.min(BatchJob.id)).group_by(BatchJob.email)) + ).all() + + if len(batch_jobs) == 0: break for batch_job in batch_jobs: