Skip to content

Commit

Permalink
try to fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon committed Sep 7, 2019
1 parent 6d081a7 commit e590198
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions observation_portal/common/state_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def debit_ipp_time(request_group):
return
try:
logger.warn("debit_ipp_time getting time allocations")
time_allocations = request_group.timeallocations
time_allocations = request_group.timeallocations.select_for_update()
time_allocations_dict = {
TimeAllocationKey(ta.semester.id, ta.instrument_type): ta for ta in time_allocations.all()
}
Expand All @@ -167,7 +167,7 @@ def debit_ipp_time(request_group):
time_allocations_dict[tak].ipp_time_available -= (ipp_value * duration_hours)
logger.warn("debit_ipp_time saving time allocation")
time_allocations_dict[tak].save()

except Exception as e:
logger.warning(_(
f'Problem debiting ipp on creation for request_group {request_group.id} on proposal '
Expand All @@ -183,7 +183,7 @@ def modify_ipp_time_from_requests(ipp_val, requests_list, modification='debit'):
return
try:
for request in requests_list:
time_allocations = request.timeallocations
time_allocations = request.timeallocations.select_for_update()
for time_allocation in time_allocations:
duration_hours = request.duration / 3600
modified_time = time_allocation.ipp_time_available
Expand Down
4 changes: 2 additions & 2 deletions observation_portal/observations/time_accounting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

logger = logging.getLogger()


@transaction.atomic
def on_summary_update_time_accounting(current, instance):
""" Whenever a summary is created or updated, do time accounting based on the completed time """
observation_type = instance.configuration_status.observation.request.request_group.observation_type
Expand All @@ -24,7 +24,7 @@ def on_summary_update_time_accounting(current, instance):

if time_difference:
with transaction.atomic():
time_allocations = instance.configuration_status.observation.request.timeallocations
time_allocations = instance.configuration_status.observation.request.timeallocations.select_for_update()
for time_allocation in time_allocations:
if time_allocation.instrument_type.upper() == instance.configuration_status.configuration.instrument_type.upper():
if observation_type == RequestGroup.NORMAL:
Expand Down

0 comments on commit e590198

Please sign in to comment.