Skip to content

Commit 9a5e51a

Browse files
Fix behaviour when initial sessions is set to 0, meaning creation of reserved sessions should be delayed.
1 parent 95e2762 commit 9a5e51a

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

training-portal/src/project/apps/workshops/manager/sessions.py

+18
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,15 @@ def initiate_reserved_sessions(portal):
381381
if environment.reserved == 0:
382382
continue
383383

384+
# If initial number of sessions is 0 and no workshop sessions
385+
# have yet been created, then skip to next one, as will only go
386+
# on to create reserved sessions when the first request for a
387+
# session arrives.
388+
389+
if environment.initial == 0:
390+
if environment.all_sessions_count() == 0:
391+
continue
392+
384393
# If already at capacity, skip to next one.
385394

386395
spare_capacity = environment.capacity - environment.active_sessions_count()
@@ -424,6 +433,15 @@ def initiate_reserved_sessions(portal):
424433
if environment.reserved == 0:
425434
continue
426435

436+
# If initial number of sessions is 0 and no workshop sessions
437+
# have yet been created, then skip to next one, as will only go
438+
# on to create reserved sessions when the first request for a
439+
# session arrives.
440+
441+
if environment.initial == 0:
442+
if environment.all_sessions_count() == 0:
443+
continue
444+
427445
# If already have required number of reserved sessons, skip to
428446
# next one.
429447

training-portal/src/project/apps/workshops/models.py

+46
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,30 @@ def active_sessions_count(self):
262262

263263
active_sessions_count.short_description = "Active"
264264

265+
def all_sessions(self):
266+
"""Returns the set of all workshop sessions across all workshop
267+
environments. This includes any reserved workshop sessions that have
268+
not as yet been allocated to a user, workshop sessions which are
269+
currently being shutdown, as well as stopped workshop sessions that
270+
haven't been purged.
271+
272+
"""
273+
274+
return Session.objects.filter(environment__portal=self)
275+
276+
def all_sessions_count(self):
277+
"""Returns the count of all workshop sessions across all workshop
278+
environments. This includes any reserved workshop sessions that have
279+
not as yet been allocated to a user, workshop sessions which are
280+
currently being shutdown, as well as stopped workshop sessions that
281+
haven't been purged.
282+
283+
"""
284+
285+
return self.total_sessions().count()
286+
287+
all_sessions_count.short_description = "Total"
288+
265289
def capacity_available(self):
266290
"""Returns whether there is capacity to have another workshop session.
267291
This will always return True if no sessions maximum was specified for
@@ -499,6 +523,28 @@ def active_sessions_count(self):
499523

500524
active_sessions_count.short_description = "Active"
501525

526+
def all_sessions(self):
527+
"""Returns the set of all workshop sessions. This includes any
528+
reserved workshop sessions that have not as yet been allocated to a
529+
user, workshop sessions which are currently being shutdown, as well as
530+
stopped workshop sessions that haven't been purged.
531+
532+
"""
533+
534+
return self.session_set.all()
535+
536+
def all_sessions_count(self):
537+
"""Returns the count of all workshop sessions. This includes any
538+
reserved workshop sessions that have not as yet been allocated to a
539+
user,workshop sessions which are currently being shutdown, as well as
540+
stopped workshop sessions that haven't been purged.
541+
542+
"""
543+
544+
return self.all_sessions().count()
545+
546+
all_sessions_count.short_description = "Total"
547+
502548
def allocated_session_for_user(self, user):
503549
"""Returns any allocated workshop session for the defined user. There
504550
should only be at most one, so only need to return the first if one

0 commit comments

Comments
 (0)