Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@
import usfmtools.src.verifyUSFM as verifyUSFM
import os
import tempfile
import urllib.request
from azure.monitor.opentelemetry import configure_azure_monitor

# Initialize OpenTelemetry / Azure Monitor as early as possible so that
# instrumentation can wrap Azure SDKs and other libraries imported later.
if os.environ.get("APPLICATIONINSIGHTS_CONNECTION_STRING"):
try:
configure_azure_monitor()
except Exception:
# If OTEL setup fails, continue without crashing the listener.
pass
# Try to auto-instrument `requests` library for outgoing HTTP calls.
try:
from opentelemetry.instrumentation.requests import RequestsInstrumentor
RequestsInstrumentor().instrument()
except Exception:
# best-effort only
pass
from urllib.parse import urlparse
from azure.servicebus import ServiceBusClient, ServiceBusMessage, AutoLockRenewer
from azure.storage.blob import BlobServiceClient
Expand All @@ -15,7 +31,6 @@
import shutil
import logging
from typing import Optional, Callable
from azure.monitor.opentelemetry import configure_azure_monitor

class ScanResult:
def __init__(self):
Expand Down Expand Up @@ -65,6 +80,17 @@ def error(self, msg:str, errorId:float):
def progress(self, msg:str):
if self.progress_callback:
self.progress_callback(msg)
class FakeSaidWords:
def addWord(self, word: str):
pass

class FakeManifestYaml:
def addProject(self, project):
pass
def load(self, directory: str):
pass
def save(self):
pass

def scan_dir(directory:str, listener: ResultsListener):
verifyUSFM.config = {
Expand All @@ -74,7 +100,11 @@ def scan_dir(directory:str, listener: ResultsListener):
verifyUSFM.state = verifyUSFM.State()
verifyUSFM.std_titles = []
verifyUSFM.listener = listener
verifyUSFM.saidwords = FakeSaidWords()
verifyUSFM.manifestyaml = FakeManifestYaml()
verifyUSFM.suppress = [False] * 13
verifyUSFM.verifyDir(directory)
print(verifyUSFM.suppress)


def upload_to_blob_storage(data: str, container_name: str, blob_name: str) -> None:
Expand All @@ -96,9 +126,6 @@ def upload_to_blob_storage(data: str, container_name: str, blob_name: str) -> No


def listen_for_messages():
app_insights_key = os.environ.get("APPLICATIONINSIGHTS_CONNECTION_STRING")
if app_insights_key != None and app_insights_key != "":
configure_azure_monitor()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
topicName = "WACSEvent"
Expand All @@ -112,7 +139,7 @@ def listen_for_messages():
raise_errors = os.environ.get("DEBUG_RAISE_ERRORS", "False")
renewer = AutoLockRenewer()
with ServiceBusClient.from_connection_string(connstr) as client:
with client.get_subscription_receiver(topicName, subscriptionName, uamqp_transport=True) as receiver:
with client.get_subscription_receiver(topicName, subscriptionName) as receiver:
for message in receiver:
# Register the autolocker for 7200 seconds which is 2 hours
renewer.register(receiver, message, max_lock_renewal_duration=7200)
Expand Down Expand Up @@ -164,6 +191,7 @@ def listen_for_messages():
with client.get_topic_sender(resultTopicName) as sender:
sender.send_messages(ServiceBusMessage(json.dumps({"User": user, "Repo": repo, "RepoId": id, "ResultsFileUrl": uploaded_url})))
receiver.complete_message(message)
logger.info(f"Completed processing message for {user}/{repo}")

if __name__ == "__main__":
listen_for_messages()
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ azure-core==1.30.2
azure-core-tracing-opentelemetry==1.0.0b11
azure-monitor-opentelemetry==1.6.2
azure-monitor-opentelemetry-exporter==1.0.0b28
azure-servicebus==7.13.0
azure-servicebus==7.14.3
azure-storage-blob==12.22.0
certifi==2024.7.4
cffi==1.17.1
Expand Down
2 changes: 1 addition & 1 deletion usfmtools
Submodule usfmtools updated 65 files
+2 −0 .gitignore
+17 −0 README.md
+16 −11 misc/removelines.py
+206 −0 misc/streamEdit.py
+83 −39 src/configmanager.py
+589 −322 src/footnotes.py
+190 −80 src/g_MarkParagraphs.py
+57 −31 src/g_UsfmCleanup.py
+11 −15 src/g_paratext2usfm.py
+15 −16 src/g_plaintext2usfm.py
+11 −18 src/g_selectProcess.py
+55 −26 src/g_step.py
+65 −29 src/g_txt2USFM.py
+7 −6 src/g_usfm2usx.py
+9 −9 src/g_usx2usfm.py
+6 −14 src/g_util.py
+7 −8 src/g_verifyManifest.py
+163 −123 src/g_verifyUSFM.py
+11 −12 src/g_word2text.py
+18 −12 src/inventory_chapter_labels.py
+0 −9 src/inventory_cl_1.py
+0 −9 src/inventory_cl_2.py
+100 −0 src/languageinfo.py
+0 −182 src/listFootnotes.py
+89 −0 src/manifestjson.py
+169 −40 src/manifestyaml.py
+291 −171 src/mark_paragraphs.py
+3 −7 src/parseUsfm.py
+123 −103 src/plaintext2usfm.py
+166 −59 src/projectinfo.py
+63 −39 src/quotes.py
+51 −40 src/section_titles.py
+15 −14 src/sentences.py
+0 −190 src/streamEdit.py
+6 −2 src/substitutions.py
+498 −375 src/txt2USFM.py
+39 −54 src/usfm2rc.py
+20 −34 src/usfm2usx.py
+164 −0 src/usfmReader.py
+50 −19 src/usfmWriter.py
+287 −147 src/usfm_cleanup.py
+20 −0 src/usfm_utils.py
+3 −2 src/usfm_verses.py
+85 −2 src/usfm_wizard version history.md
+48 −38 src/usfm_wizard.py
+46 −62 src/verifyManifest.py
+763 −440 src/verifyUSFM.py
+1,058 −0 src/verse_length.py
+84 −0 tests/test_Token.py
+108 −0 tests/test_configmanager.py
+83 −0 tests/test_footnotes.py
+161 −0 tests/test_languageInfo.py
+36 −0 tests/test_manifestjson.py
+202 −35 tests/test_manifestyaml.py
+44 −0 tests/test_mark_paragraphs.py
+24 −3 tests/test_plaintext2usfm.py
+212 −59 tests/test_projectinfo.py
+54 −19 tests/test_quotes.py
+83 −75 tests/test_section_titles.py
+34 −29 tests/test_sentences.py
+370 −42 tests/test_txt2usfm.py
+258 −0 tests/test_usfmReader.py
+32 −0 tests/test_usfm_utils.py
+250 −48 tests/test_usfmcleanup.py
+98 −11 tests/test_verifyUsfm.py