diff --git a/training-portal/src/project/apps/workshops/manager/portal.py b/training-portal/src/project/apps/workshops/manager/portal.py index d7318f4e..e5900f5d 100644 --- a/training-portal/src/project/apps/workshops/manager/portal.py +++ b/training-portal/src/project/apps/workshops/manager/portal.py @@ -116,8 +116,12 @@ def workshop_configuration(portal, workshop): workshop["capacity"] = max(0, workshop["capacity"]) workshop["reserved"] = max(0, min(workshop["reserved"], workshop["capacity"])) + # Note that it is okay that initial is greater than reserved. In this + # case application of reserved limit will only be applied after those + # initial sessions has been used up. + workshop["initial"] = max(0, min(workshop["initial"], workshop["capacity"])) - workshop["initial"] = min(workshop["initial"], workshop["reserved"]) + workshop["initial"] = max(workshop["initial"], workshop["reserved"]) workshop.setdefault("expires", portal.default_expires) workshop.setdefault("orphaned", portal.default_orphaned) diff --git a/training-portal/src/project/apps/workshops/manager/sessions.py b/training-portal/src/project/apps/workshops/manager/sessions.py index ab025e8f..399aa47e 100644 --- a/training-portal/src/project/apps/workshops/manager/sessions.py +++ b/training-portal/src/project/apps/workshops/manager/sessions.py @@ -332,6 +332,20 @@ def terminate_reserved_sessions(portal): # they are over what is allowed for that workshop environment. for environment in portal.running_environments(): + # If initial number of sessions is greater than reserved sessions then + # don't reconcile until after number of sessions would fall below the + # required reserved number. Note that this doesn't really deal properly + # with where sessions are purged after some time and so count of all + # sessions drops back to zero. Should really look at number of sessions + # created over time, rather than how many exist right now. + + if environment.initial > environment.reserved: + excess = environment.initial - environment.reserved + if environment.all_sessions_count() < excess: + continue + if environment.available_sessions_count() > environment.reserved: + continue + excess = max(0, environment.available_sessions_count() - environment.reserved) for session in islice(environment.available_sessions(), 0, excess):