Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testactions #40

Closed
wants to merge 15 commits into from
45 changes: 45 additions & 0 deletions .github/workflows/productionworkflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Test Production

on:
pull_request:
branches:
- main

jobs:
test-production:
runs-on: ubuntu-latest
env:
db_name: ${{ secrets.DB_NAME }}
MONGO_URI_NAACP: ${{ secrets.MONGO_URI_NAACP }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ./se_ml_production/ML_backend_GKE/ML_GKE/ML_Service_GKE/requirements.txt

- name: Google Auth
id: auth
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}

- name: Run deployment
id: deployment
run: |
python ./se_ml_production/ML_backend_GKE/ML_GKE/ML_Service_GKE/main.py
if grep -q "Deployment Test Comlpete with no erors" deployment.log; then
echo "Deployment Test Complete with no errors"
exit 0
else
echo "Deployment Test Failed"
exit 1
fi
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ secret.py
testing-ner.ipynb
keys/
env.sh
.env

# Mill
combine_rss_articles.ipynb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from art import *
from bson import ObjectId
from pymongo import MongoClient
import sys

from google.cloud import storage
from Utils.spinner import Spinner
Expand Down Expand Up @@ -85,6 +86,7 @@ def bootstrap_MongoDB_Prod(client, defined_collection_names):
db_prod.create_collection(collection)
print(f"[INFO] Collection '{collection}' created.")
spinner.stop()
sys.stdout.write("Deployment Test Comlpete with no erors\n")
except Exception as err:
spinner.err()
print(f"[Error!] Error in Bootstrapping MongoDB Prod DB\nError: {err}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from ML_API import ml_router
from global_state import global_instance
from bootstrappers import bootstrap_pipeline, validate_bootstrap, bootstrap_MongoDB_Prod
import sys

app.include_router(ml_router)

Expand Down Expand Up @@ -38,6 +39,7 @@ async def startup_event():
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000) # This bootstraps the FastAPI




Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pandas as pd
from tqdm import tqdm
import os


import secret
from global_state import global_instance
from processingUtils import get_sentences, get_snippet, check_snippets, run_entity_recognition, run_pipeline

Expand Down Expand Up @@ -70,7 +71,7 @@ def process_data(chunk, df, data_schema, data_packaging_scheme, nlp_ner):
]

for (entities, method) in check_order:
check_text, location_geocode, existing_loc_geocode = check_snippets(secret.API_KEY, entities[1], entities[0])
check_text, location_geocode, existing_loc_geocode = check_snippets(os.environ['API_KEY'], entities[1], entities[0])
if not check_text:
discarded_articles.append(df['Tagging'][idx])
break
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import secret
import os
from pymongo import MongoClient

def connect_MongoDB_Prod():
try:
client = MongoClient(secret.MONGO_URI_NAACP)
client = MongoClient(os.environ['MONGO_URI_NAACP'])
db = client['se_naacp_db']
return db
except Exception as err:
Expand All @@ -12,7 +12,7 @@ def connect_MongoDB_Prod():

def update_job_status(client, upload_id, user_id, timestamp, article_cnt, status, message):
try:
db = client[secret.db_name]
db = client[os.environ['db_name']]

upload_collection = db["uploads"]
if (upload_collection.find_one({'uploadID': upload_id})):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import secret
from datetime import datetime
from global_state import global_instance
from Mongo_Utils.mongo_funcs import connect_MongoDB_Prod
import os

def convert_to_datesum(s):
date_formatted = s.replace('-', '').replace(' ', '').replace(':', '')
Expand Down Expand Up @@ -34,7 +34,7 @@ def addExistingTracts(tract_collection):
def send_Discarded(client, discard_list):
try:
# Pack and send all articles
db_prod = client[secret.db_name]
db_prod = client[os.environ['db_name']]

discarded_collection_name = "discarded"
discarded_collection = db_prod[discarded_collection_name]
Expand Down Expand Up @@ -62,7 +62,7 @@ def send_Discarded(client, discard_list):
# ==== Packing Funcs ====
def send_to_production(client, df):
try:
db_prod = client[secret.db_name]
db_prod = client[os.environ['db_name']]

# Pack and send all articles
pack_articles(db_prod, df)
Expand All @@ -84,22 +84,24 @@ def pack_articles(db_prod, df):
collection_list = db_prod.list_collection_names()

if articles_collection_name not in collection_list:
db_prod.create_collection(articles_collection_name)
print(f"[INFO] Collection '{articles_collection_name}' created.")
db_prod.create_collection(articles_collection_name)
print(f"[INFO] Collection '{articles_collection_name}' created.")

article_df = df.set_index('id')
article_dict = article_df.T.to_dict('dict')

for article_key in article_dict.keys():
article = article_dict[article_key]
if ('openai_labels' not in article):
article["openai_labels"] = []
else:
article["openai_labels"] = string_to_list(article["openai_labels"])
article["dateSum"] = convert_to_datesum(article["pub_date"])
article_payload.append(article)
article = article_dict[article_key]
if ('openai_labels' not in article):
article["openai_labels"] = []
else:
article["openai_labels"] = string_to_list(article["openai_labels"])
article["dateSum"] = convert_to_datesum(article["pub_date"])
article_payload.append(article)

articles_collection.insert_many(article_payload)


print("[INFO] Articles Successfully inserted!")
return
except Exception as err:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import json
import zipfile
import secret
from art import *
from bson import ObjectId
from pymongo import MongoClient
Expand Down Expand Up @@ -235,7 +234,7 @@ def bootstrap_MongoDB_Prod(client, defined_collection_names):
if (client == None):
raise Exception("No database was given!")

db_prod = client[secret.db_name]
db_prod = client[os.environ['db_name']]

# Here we check for the upload collection and make it if it doesn't exist
collection_list = db_prod.list_collection_names()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import secret
import os
import pandas as pd
from io import StringIO # Import StringIO
from fastapi import UploadFile # For typing
Expand Down Expand Up @@ -26,7 +26,7 @@ def is_duplicate_discarded(tag, discarded_collection):
return discarded_collection.count_documents(queryDiscarded) > 0

def run_validation(client, df):
db_prod = client[secret.db_name]
db_prod = client[os.environ['db_name']]
collection_list = db_prod.list_collection_names()

if ('articles_data' in collection_list):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from google.cloud import pubsub_v1

import nltk
import secret
from ML_Entry import run_pipeline
from global_state import global_instance
from Mongo_Utils.mongo_funcs import connect_MongoDB_Prod
Expand Down Expand Up @@ -73,7 +72,7 @@ def startup_event():
db_prod = connect_MongoDB_Prod()
db_manager = global_instance.get_data("db_manager")
# We then create our first MongoDB connection
db_manager.init_connection(uri=secret.MONGO_URI_NAACP)
db_manager.init_connection(uri=os.environ['MONGO_URI_NAACP'])

db_manager.run_job(
bootstrap_MongoDB_Prod,
Expand Down
Loading