ChandimaPrabath commited on
Commit
82d44ca
·
1 Parent(s): 53dc202

0.0.2.5 V Beta

Browse files
Files changed (1) hide show
  1. LoadBalancer.py +9 -8
LoadBalancer.py CHANGED
@@ -1,7 +1,7 @@
1
  import os
2
- import requests
3
  import json
4
  import urllib.request
 
5
  from tqdm import tqdm
6
  from indexer import indexer
7
  import re
@@ -9,7 +9,7 @@ from tvdb import fetch_and_cache_json
9
  from threading import Event
10
  import time
11
  import logging
12
- from threading import Thread, Event, Timer
13
  from api import InstancesAPI
14
 
15
 
@@ -18,8 +18,8 @@ CACHE_DIR = os.getenv("CACHE_DIR")
18
  download_progress = {}
19
 
20
  class LoadBalancer:
21
- def __init__(self, cache_dir, index_file, token, repo, polling_interval=1, max_retries=3, initial_delay=1):
22
- self.version = "0.0.2.4 V Beta"
23
  self.instances = []
24
  self.instances_health = {}
25
  self.polling_interval = polling_interval
@@ -78,7 +78,7 @@ class LoadBalancer:
78
 
79
  def get_reports(self):
80
  reports = self.instances_api.fetch_reports()
81
-
82
  # Initialize temporary JSON data holders
83
  temp_film_store = {}
84
  temp_tv_store = {}
@@ -92,9 +92,10 @@ class LoadBalancer:
92
  logging.error(f"Failed to get report from {instance_url}. Removing instance.")
93
  self.remove_instance(instance_url)
94
 
95
- # Compare and update actual JSON files after processing all reports
96
- self.update_film_store_json(temp_film_store)
97
- self.update_tv_store_json(temp_tv_store)
 
98
 
99
  def process_report(self, instance_url, report, temp_film_store, temp_tv_store):
100
  film_store = report.get('film_store', {})
 
1
  import os
 
2
  import json
3
  import urllib.request
4
+ import concurrent.futures
5
  from tqdm import tqdm
6
  from indexer import indexer
7
  import re
 
9
  from threading import Event
10
  import time
11
  import logging
12
+ from threading import Thread, Event
13
  from api import InstancesAPI
14
 
15
 
 
18
  download_progress = {}
19
 
20
  class LoadBalancer:
21
+ def __init__(self, cache_dir, index_file, token, repo, polling_interval=2, max_retries=3, initial_delay=1):
22
+ self.version = "0.0.2.5 V Beta"
23
  self.instances = []
24
  self.instances_health = {}
25
  self.polling_interval = polling_interval
 
78
 
79
  def get_reports(self):
80
  reports = self.instances_api.fetch_reports()
81
+
82
  # Initialize temporary JSON data holders
83
  temp_film_store = {}
84
  temp_tv_store = {}
 
92
  logging.error(f"Failed to get report from {instance_url}. Removing instance.")
93
  self.remove_instance(instance_url)
94
 
95
+ # Use concurrent.futures to update JSON files in separate threads without waiting
96
+ with concurrent.futures.ThreadPoolExecutor() as executor:
97
+ executor.submit(self.update_film_store_json, temp_film_store)
98
+ executor.submit(self.update_tv_store_json, temp_tv_store)
99
 
100
  def process_report(self, instance_url, report, temp_film_store, temp_tv_store):
101
  film_store = report.get('film_store', {})