Skip to content

Commit 1de70ac

Browse files
committed
provider: remove lock logic
efficiency no thanks its too complicated.
1 parent 2ce3cc0 commit 1de70ac

File tree

1 file changed

+1
-46
lines changed

1 file changed

+1
-46
lines changed

src/adsb_api/utils/provider.py

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,7 @@
2222

2323

2424
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+
...
5126
class Provider(Base):
5227
def __init__(self, enabled_bg_tasks):
5328
self.aircrafts = {}
@@ -100,10 +75,6 @@ async def shutdown(self):
10075
async def fetch_hub_stats(self):
10176
try:
10277
while True:
103-
if not await self._lock("hub_stats"):
104-
print(f"hub_stats not Locked...")
105-
await asyncio.sleep(5)
106-
continue
10778
try:
10879
async with self.client_session.get(STATS_URL) as resp:
10980
data = await resp.json()
@@ -119,10 +90,6 @@ async def fetch_hub_stats(self):
11990
async def fetch_ingest(self):
12091
try:
12192
while True:
122-
if not await self._lock("ingest"):
123-
print(f"ingest not Locked...")
124-
await asyncio.sleep(5)
125-
continue
12693
try:
12794
ips = [
12895
record.host
@@ -173,10 +140,6 @@ async def fetch_ingest(self):
173140
async def fetch_mlat(self):
174141
try:
175142
while True:
176-
if not await self._lock("mlat"):
177-
print(f"mlat not Locked...")
178-
await asyncio.sleep(5)
179-
continue
180143
try:
181144
data_per_server = {}
182145
for server in MLAT_SERVERS:
@@ -399,10 +362,6 @@ async def download_csv_to_import(self):
399362
async def _background_task(self):
400363
try:
401364
while True:
402-
if not await self._lock("background_vrs"):
403-
print(f"background_vrs not Locked...")
404-
await asyncio.sleep(5)
405-
continue
406365
try:
407366
await self.download_csv_to_import()
408367
await asyncio.sleep(3600)
@@ -554,10 +513,6 @@ async def _update_aircrafts(self, ip):
554513
async def _background_task(self):
555514
try:
556515
while True:
557-
if not await self._lock("background_feederdata"):
558-
print(f"background_feederdata not Locked...")
559-
await asyncio.sleep(5)
560-
continue
561516
try:
562517
ips = [
563518
record.host

0 commit comments

Comments
 (0)