Skip to content

Commit

Permalink
Add environment variables for diff cases
Browse files Browse the repository at this point in the history
  • Loading branch information
malvads committed Sep 28, 2023
1 parent 0d2b317 commit 1c455c9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Run outliers
run: |
python3.8 resources/src/__main__.py --test
ENVIRONMENT=test python3.8 resources/src/__main__.py
15 changes: 9 additions & 6 deletions resources/src/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,29 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import sys
import os
from Logger.logger import logger
from server.rest import APIServer, config
from server.production import GunicornApp

class Outliers:
def __init__(self) -> None:
self.environment = os.environ.get("ENVIRONMENT", "development")
self.server = None
self.app = None
self.run()

def run(self):
if "--prod" in sys.argv:
if "production" in self.environment:
self.run_production_server()
else:
self.run_test_server()
if "development" in self.environment:
self.run_test_server(False)
if "test" in self.environment:
self.run_test_server(True)

def run_test_server(self):
def run_test_server(self, test_run_github_action):
self.api = APIServer()
self.api.start_test_server()
self.api.start_test_server(test_run_github_action)

def run_production_server(self):
logger.info("Starting Outliers API REST")
Expand Down
2 changes: 1 addition & 1 deletion resources/src/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ outliers_server_port=39091
metric = bytes

[Druid]
druid_endpoint = http://x.x.x.x:8080/druid/v2/
druid_endpoint = http://10.0.209.10:8080/druid/v2/

[Logger]
log_file = ./outliers.log
21 changes: 14 additions & 7 deletions resources/src/server/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,18 @@ def calculate():
return jsonify(outliers.Autoencoder.return_error())

def run_test_app(self):
self.app.run(debug=False, host=config.get("OutliersServerTesting", "outliers_binding_address"), port=config.get("OutliersServerTesting", "outliers_server_port"))
try:
self.app.run(debug=False, host=config.get("OutliersServerTesting", "outliers_binding_address"), port=config.get("OutliersServerTesting", "outliers_server_port"))
except Exception as e:
logger.logger.error(f"Exception in server thread: {e}")
self.exit_code = 1

def start_test_server(self):
self.server_thread = threading.Thread(target=self.run_test_app)
self.server_thread.daemon = True
self.server_thread.start()
time.sleep(30)
sys.exit(self.exit_code)
def start_test_server(self, test_run_github_action):
if test_run_github_action:
self.server_thread = threading.Thread(target=self.run_test_app)
self.server_thread.daemon = True
self.server_thread.start()
time.sleep(30)
sys.exit(self.exit_code)
else:
self.run_test_app()
2 changes: 1 addition & 1 deletion resources/systemd/rb-aioutliers.service
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Group=root
KillSignal=SIGTERM # Use SIGTERM for graceful termination
Type=simple

ExecStart=/usr/bin/scl enable rh-python38 -- python3 /opt/rb-aioutliers/resources/src/__main__.py --prod
ExecStart=/usr/bin/scl enable rh-python38 -- ENVIRONMENT=production python3 /opt/rb-aioutliers/resources/src/__main__.py

TimeoutStopSec=60

Expand Down

0 comments on commit 1c455c9

Please sign in to comment.