Skip to content

Commit

Permalink
Fix synchronization issue when multiple users send requests
Browse files Browse the repository at this point in the history
  • Loading branch information
subhashreddykallam committed Jan 29, 2020
1 parent 4547b60 commit 0fd6e1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions attendance/generateSSID.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ def refreshSSID(module):
time = datetime.now() - timedelta(minutes=5)
recentLogsCount = Log.objects.filter(lastSeen__gte=time).count()

module.lastRefreshTime = now.replace(second=0, microsecond=0)

if recentLogsCount == 0:
module.lastRefreshTime = now.replace(second=0, microsecond=0)
module.save()
return

# open file and move list by 1 place
Expand All @@ -28,7 +30,6 @@ def refreshSSID(module):
newSeed = generatorScript(seed)
module.SSID = 'amFOSS_' + str(newSeed)
module.seed = newSeed
module.lastRefreshTime = now.replace(second=0, microsecond=0)
with open("attendance/futureSSID.json", "r") as file:
futureSSID = json.load(file)
futureSSID = futureSSID[1:]
Expand Down
11 changes: 7 additions & 4 deletions attendance/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def mutate(self, info, username, password, list):
futureSSID.append('DummyValue2')
update_futureSSID(futureSSID)


time = datetime.now() - timedelta(minutes=5)
recentLogsCount = Log.objects.filter(lastSeen__gte=time).count()

Expand All @@ -77,10 +76,10 @@ def mutate(self, info, username, password, list):
giveAttendance = False
if recentLogsCount == 0:
currentSSID = -1
for i in list:
for sentSSID in list:
try:
if int(i.strip('amFOSS_')) in futureSSID:
currentSSID = int(i.strip('amFOSS_'))
if int(sentSSID.strip('amFOSS_')) in futureSSID:
currentSSID = int(sentSSID.strip('amFOSS_'))
except ValueError:
pass
if currentSSID != -1:
Expand All @@ -95,6 +94,10 @@ def mutate(self, info, username, password, list):

giveAttendance = True
futureSSID = ['DummyValue1', 'DummyValue2'] + futureSSID[futureSSID.index(currentSSID):]
module.SSID = 'amFOSS_' + str(futureSSID[2])
module.seed = futureSSID[2]
module.lastRefreshTime = now.replace(second=0, microsecond=0)
module.save()
with open("attendance/futureSSID.json", "w") as file:
json.dump(futureSSID, file)
else:
Expand Down

0 comments on commit 0fd6e1e

Please sign in to comment.