misc: add count parameter to BaseResource.jobs() (#87168)

It limits the number of jobs to run; it is useful for tests.
This commit is contained in:
Benjamin Dauvergne 2024-02-20 07:03:34 +01:00
parent 91b92aeb44
commit 920a871393
1 changed files with 4 additions and 1 deletions

View File

@ -607,7 +607,7 @@ class BaseResource(models.Model):
resource_type = ContentType.objects.get_for_model(self)
return Job.objects.filter(resource_type=resource_type, resource_pk=self.pk)
def jobs(self):
def jobs(self, count=-1):
# "jobs" cron job to run asynchronous tasks
if self.down():
# don't try running jobs if connector is known to be down.
@ -617,6 +617,9 @@ class BaseResource(models.Model):
skip_locked = {}
skipped_jobs = []
while True:
if count == 0:
break
count -= 1
# optimistic skip
if (
not self.jobs_set()