This is an ApiView from my django project:
JavaScript
x
16
16
1
class Receive_Payment(APIView):
2
authentication_classes = (TokenAuthentication,)
3
permission_classes = (IsAdminUser,)
4
def get(self, request, cc_number):
5
if Card.objects.filter(cc_num = cc_number).exists():
6
client = Client.objects.get(client_id = (Card.objects.get(cc_num = cc_number).client))
7
if not client.is_busy:
8
client.is_busy = True
9
client.save()
10
resp = "successful"
11
else:
12
resp = "client_is_busy"
13
else:
14
resp = "fail"
15
return Response({"response": resp})
16
As you see, if client.is_busy
is not True
, I’m making it True
in here. But in this situation, I need to client.is_busy = False
after 30 seconds. If I do it under client.save()
code, it delays to response. How can I do it?
Advertisement
Answer
You should consider using timer objects here.
e.g.
JavaScript
1
6
1
import threading
2
def free_up_client(client):
3
client.is_busy = false
4
5
timer = Theading.timer(30.0, free_up_client, [client])
6