Skip to content

Commit

Permalink
Fix handling of initial sessions where is greater than reserved.
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamDumpleton committed May 25, 2022
1 parent 313e20f commit 6d6dde6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion training-portal/src/project/apps/workshops/manager/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions training-portal/src/project/apps/workshops/manager/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 6d6dde6

Please sign in to comment.