Skip to content

Commit

Permalink
On demand resources, started via on-demand tags
Browse files Browse the repository at this point in the history
On-demand tickets need to be prioritized over the normal tickets
(priority queue), otherwise we risk that normal tickets take "on demand"
resources.

If we want to prefer one "on demand" pool over the other "on demand"
(e.g. spot AWS over normal instances), we need to sort them through a
priority queue based on tag priority.  The fallback for spawn failures
(e.g. if SPOT instances don't start) isn't resolved yet, though.

Fixes: #24
  • Loading branch information
praiskup committed Aug 3, 2023
1 parent 5ae9781 commit ac6c650
Show file tree
Hide file tree
Showing 6 changed files with 734 additions and 51 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ SHELLTEST_OPTIONS :=
SHELL_TESTS := \
basic.sh \
check.sh \
ondemand.sh \
reuse.sh

TEST_PYTHONS := python3
Expand Down
19 changes: 13 additions & 6 deletions resallocserver/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from resalloc.helpers import RState, TState
from resallocserver import models
from sqlalchemy.orm import Query
from sqlalchemy.orm import Query, joinedload

Check warning

Code scanning / vcs-diff-lint

third party import "from sqlalchemy.orm import Query, joinedload" should be placed before "from resalloc.helpers import RState, TState" Warning

third party import "from sqlalchemy.orm import Query, joinedload" should be placed before "from resalloc.helpers import RState, TState"
from sqlalchemy import or_


Expand Down Expand Up @@ -69,10 +69,11 @@ def ready(self):
"""
Get ready resources, those which were never assigned or are released.
The sandbox-assigned resources are sorted above others - so they can be
re-used first.
re-used first. The query is already ordered by ID ASC.
"""
return (self.up().filter(models.Resource.ticket_id.is_(None))
.filter(models.Resource.check_failed_count==0))
.filter(models.Resource.check_failed_count==0)
.order_by(models.Resource.id.asc()))

def taken(self):
"""
Expand Down Expand Up @@ -156,9 +157,15 @@ def kill(self, res_id):
class QTickets(QObject):
query = Query(models.Ticket)

def waiting(self):
return self.query.filter_by(resource_id=None)\
.filter_by(state=TState.OPEN)
def waiting(self, preload_tags=False):
query = (
self.query.filter_by(resource_id=None)
.filter_by(state=TState.OPEN)
)
if preload_tags:
query = query.options(joinedload("tags"))
return query


def not_closed(self):
return self.query.filter(models.Ticket.state != TState.CLOSED)
Loading

0 comments on commit ac6c650

Please sign in to comment.