Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed May 11, 2023
1 parent c65bf01 commit ffd0782
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
22 changes: 13 additions & 9 deletions share/tasks/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ def consume(self, job_id=None, exhaust=True, superfluous=False, force=False, **k
force (bool, optional):
Additional keyword arguments passed to _consume_job, along with superfluous and force
"""
with self._locked_job(job_id) as job:
with self._locked_job(job_id, force=force) as job:
if job is None:
if job_id is None:
logger.info('No %ss are currently available', self.Job.__name__)
return
else:
logger.error('Could not load/lock/consume %s(id=%s)', self.Job.__name__, job_id)
return
message = f'Could not find/lock {self.Job.__name__}(id={job_id})'
logger.error(message)
raise self.Job.DoesNotExist(message)

assert self.task or not exhaust, 'Cannot pass exhaust=True unless running in an async context'
if exhaust and job_id is None:
Expand Down Expand Up @@ -119,12 +121,14 @@ def _filter_ready(self, qs):
claimed=True
)

def _locked_job(self, job_id):
qs = (
self.Job.objects.all()
.exclude(source_config__disabled=True)
.exclude(source_config__source__is_deleted=True)
)
def _locked_job(self, job_id, force=False):
qs = self.Job.objects.all()
if not force:
qs = (
qs
.exclude(source_config__disabled=True)
.exclude(source_config__source__is_deleted=True)
)
if job_id is not None:
logger.debug('Loading %s %d', self.Job.__name__, job_id)
qs = qs.filter(id=job_id)
Expand Down
8 changes: 3 additions & 5 deletions tests/share/tasks/test_harvest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def source_config(self, class_scoped_django_db):

@pytest.mark.parametrize('source_config_kwargs, task_kwargs, lock_config, exception', [
({}, {}, True, HarvesterConcurrencyError),
({'disabled': True}, {'ignore_disabled': True}, True, HarvesterConcurrencyError),
({'source__is_deleted': True}, {'ignore_disabled': True}, True, HarvesterConcurrencyError),
({'disabled': True, 'source__is_deleted': True}, {'ignore_disabled': True}, True, HarvesterConcurrencyError),
({'disabled': True}, {}, True, HarvestJob.DoesNotExist),
({'source__is_deleted': True}, {}, True, HarvestJob.DoesNotExist),
({'disabled': True, 'source__is_deleted': True}, {}, True, HarvestJob.DoesNotExist),
])
def test_failure_cases(self, source_config_kwargs, task_kwargs, lock_config, exception):
source_config = factories.SourceConfigFactory(**source_config_kwargs)
Expand All @@ -73,8 +73,6 @@ def test_failure_cases(self, source_config_kwargs, task_kwargs, lock_config, exc
({}, {'force': True}, True),
({'disabled': True}, {'force': True}, True),
({'disabled': True}, {'force': True}, False),
({'disabled': True}, {'ignore_disabled': True}, False),
({'source__is_deleted': True}, {'ignore_disabled': True}, False),
({'source__is_deleted': True}, {'force': True}, False),
({'source__is_deleted': True}, {'force': True}, True),
])
Expand Down

0 comments on commit ffd0782

Please sign in to comment.