Browse Source

Add some recovery attempts for race condition of missing status invalidation.

feature/long-poll-status
Daniel Perelman 2 years ago
parent
commit
564d79e831
1 changed files with 18 additions and 0 deletions
  1. +18
    -0
      fear_tracker/views.py

+ 18
- 0
fear_tracker/views.py View File

@@ -158,6 +158,12 @@ def game_status_object(game, current_phase=None, players_with_fear=None):
status_hash = h.hexdigest()
status_obj['hash'] = status_hash

async_to_sync(get_channel_layer().group_send)(
"%s_status" % game.access_code, {
"type": "fear_tracker.hashcode_seen",
"hashcode": status_hash,
})

return status_obj


@@ -343,6 +349,11 @@ class StatusLongPollConsumer(AsyncHttpConsumer):

await self.channel_layer.group_add("%s_status" % self.access_code,
self.channel_name)
await self.channel_layer.group_send(
"%s_status" % self.access_code, {
"type": "fear_tracker.hashcode_seen",
"hashcode": self.hashcode,
})

async def http_request(self, message):
"""
@@ -358,6 +369,13 @@ class StatusLongPollConsumer(AsyncHttpConsumer):
await self.channel_layer.group_discard("%s_status" % self.access_code,
self.channel_name)

async def fear_tracker_hashcode_seen(self, event):
if self.hashcode != event["hashcode"]:
await self.channel_layer.group_send(
"%s_status" % self.access_code, {
"type": "fear_tracker.invalidate_status",
})

async def fear_tracker_invalidate_status(self, event):
no_hash_status = reverse('status',
kwargs={'access_code': self.access_code})


Loading…
Cancel
Save