22
22
23
23
24
24
class Base :
25
- async def _lock (self , name ):
26
- key = f"lock:{ name } "
27
- value = gethostname ()
28
-
29
- if not isinstance (self .redis , redis .Redis ):
30
- print ("Lock: Redis is not connected" )
31
- return False
32
- try :
33
- print (f"Trying to Lock { key } as { value } " )
34
- if await self .redis .set (key , value , nx = True , ex = 10 ):
35
- print (f"Locked { key } :{ value } " )
36
- return True
37
-
38
- current_locker = await self .redis .get (key )
39
- if current_locker is None :
40
- print (f"Lock { name } is not locked" )
41
- return False
42
- current_locker = current_locker .decode ()
43
- if current_locker == value :
44
- print (f"Already Locked { key } " )
45
- return True
46
- print (f"Lock { name } is locked by { current_locker } " )
47
- return False
48
- except Exception as e :
49
- print ("Error Locking:" , e )
50
- return False
25
+ ...
51
26
class Provider (Base ):
52
27
def __init__ (self , enabled_bg_tasks ):
53
28
self .aircrafts = {}
@@ -100,10 +75,6 @@ async def shutdown(self):
100
75
async def fetch_hub_stats (self ):
101
76
try :
102
77
while True :
103
- if not await self ._lock ("hub_stats" ):
104
- print (f"hub_stats not Locked..." )
105
- await asyncio .sleep (5 )
106
- continue
107
78
try :
108
79
async with self .client_session .get (STATS_URL ) as resp :
109
80
data = await resp .json ()
@@ -119,10 +90,6 @@ async def fetch_hub_stats(self):
119
90
async def fetch_ingest (self ):
120
91
try :
121
92
while True :
122
- if not await self ._lock ("ingest" ):
123
- print (f"ingest not Locked..." )
124
- await asyncio .sleep (5 )
125
- continue
126
93
try :
127
94
ips = [
128
95
record .host
@@ -173,10 +140,6 @@ async def fetch_ingest(self):
173
140
async def fetch_mlat (self ):
174
141
try :
175
142
while True :
176
- if not await self ._lock ("mlat" ):
177
- print (f"mlat not Locked..." )
178
- await asyncio .sleep (5 )
179
- continue
180
143
try :
181
144
data_per_server = {}
182
145
for server in MLAT_SERVERS :
@@ -399,10 +362,6 @@ async def download_csv_to_import(self):
399
362
async def _background_task (self ):
400
363
try :
401
364
while True :
402
- if not await self ._lock ("background_vrs" ):
403
- print (f"background_vrs not Locked..." )
404
- await asyncio .sleep (5 )
405
- continue
406
365
try :
407
366
await self .download_csv_to_import ()
408
367
await asyncio .sleep (3600 )
@@ -554,10 +513,6 @@ async def _update_aircrafts(self, ip):
554
513
async def _background_task (self ):
555
514
try :
556
515
while True :
557
- if not await self ._lock ("background_feederdata" ):
558
- print (f"background_feederdata not Locked..." )
559
- await asyncio .sleep (5 )
560
- continue
561
516
try :
562
517
ips = [
563
518
record .host
0 commit comments