=== modified file 'lava_scheduler_daemon/dbjobsource.py'
@@ -89,15 +89,17 @@
jobs_for_device = jobs_for_device.extra(
select={
'is_targeted': 'requested_device_id is not NULL',
- 'missing_tags': '''
- select count(*) from lava_scheduler_app_testjob_tags
- where testjob_id = lava_scheduler_app_testjob.id
- and tag_id not in (select tag_id
- from lava_scheduler_app_device_tags
- where device_id = '%s')
- ''' % device.hostname,
},
- where=['missing_tags = 0'],
+ where=[
+ # In human language, this is saying "where the number of
+ # tags that are on the job but not on the device is 0"
+ '''(select count(*) from lava_scheduler_app_testjob_tags
+ where testjob_id = lava_scheduler_app_testjob.id
+ and tag_id not in (select tag_id
+ from lava_scheduler_app_device_tags
+ where device_id = '%s')) = 0'''
+ % device.hostname,
+ ],
order_by=['-is_targeted', 'submit_time'])
jobs = jobs_for_device[:1]
if jobs: