Skip to content
Snippets Groups Projects
Commit d718632d authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

fix is_playing on server

parent 7c08d2e0
No related branches found
No related tags found
1 merge request!9Release
Pipeline #15169 passed
......@@ -152,19 +152,12 @@ $(window).ready(
if ("is_running" in data) {
if (data["is_running"]) {
// Reset if we are playing again.
// Don't do anything if we have reached an inconsistent state,
// where the timer is at 0 but server still reports it playing.
// This will be resolved within a few milliseconds.
const remainingTime = window.timer.getTimeValues()
if (remainingTime.seconds === 0 && remainingTime.minutes === 0) {
window.timer = new Timer({
countdown: true,
startValues: {
minutes: window.startingTime.minutes,
seconds: window.startingTime.seconds,
}
})
assignEventListeners()
}
window.timer.start()
......
......@@ -11,6 +11,20 @@ from channels.generic.websocket import AsyncWebsocketConsumer
running_timer_threads = []
def handle_expired_timer(timer) -> bool:
if timer.minutes == 0 and timer.seconds == 0:
# Stop the thread if we have reached the end
timer.is_running = False
timer.save()
running_timer_threads.remove(timer.id)
return True
return False
def tick_timer(timer, iteration: int, total_seconds: int) -> None:
second_compensation = 0
......@@ -32,26 +46,10 @@ def tick_timer(timer, iteration: int, total_seconds: int) -> None:
running_timer_threads.remove(timer.id)
return
if timer.minutes == 0 and timer.seconds == 0:
# Stop the thread if we have reached the end
running_timer_threads.remove(timer.id)
return
handle_expired_timer(timer)
start_time = timeit.default_timer()
print(timer.minutes, timer.seconds)
if timer.minutes == 0 and timer.seconds == 0:
# Stop the thread if we have reached the end
timer.is_running = False
timer.save()
running_timer_threads.remove(timer.id)
return
if iteration != timer.iteration:
# Stop the thread if there is a new timer
......@@ -66,6 +64,8 @@ def tick_timer(timer, iteration: int, total_seconds: int) -> None:
timer.minutes = minutes
timer.seconds = seconds
handle_expired_timer(timer)
timer.save()
end_time = timeit.default_timer()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment