SIENTIAPDE-1445
SIENTIAPDE-1445 Add PI Web API configuration to .env.example and enhance worker setup - Introduced new environment variables for PI Web API configuration in .env.example. - Updated prepare_worker.py to utilize a camelCase to kebab-case conversion function for queue naming. - Enhanced logging in prepare_worker to provide better insights during worker preparation. - Adjusted execution counts in tests.ipynb for improved notebook state management.
This commit is contained in:
@@ -19,6 +19,10 @@ REDIS_PASSWORD="pass"
|
||||
TEMPORAL_HOST=localhost:7233
|
||||
TEMPORAL_NAMESPACE=scouter
|
||||
|
||||
PI_WEB_API_BASE_URL="https://piwebapi.link.com/piwebapi"
|
||||
PI_WEB_API_AUTH_TYPE="basic"
|
||||
PI_WEB_API_AUTH_TOKEN="password"
|
||||
|
||||
LOG_LEVEL=INFO
|
||||
|
||||
PROJECT_NAME=scouter
|
||||
|
||||
@@ -5,6 +5,10 @@ from typing import Any
|
||||
from temporalio.client import Client
|
||||
from temporalio.worker import PollerBehaviorAutoscaling, Worker
|
||||
|
||||
from sientia_do.observability.logger import Logger
|
||||
|
||||
import re
|
||||
|
||||
parameters = [
|
||||
('MAX_CONCURRENT_WORKFLOW_TASKS', '200'),
|
||||
('MAX_CONCURRENT_ACTIVITIES', '200'),
|
||||
@@ -18,16 +22,25 @@ parameters = [
|
||||
('ACTIVITY_POLLER_BEHAVIUR_MAXIMUM', '200'),
|
||||
]
|
||||
|
||||
import re
|
||||
|
||||
def camel_to_kebab(text: str) -> str:
|
||||
"""Convert camelCase or PascalCase to kebab-case."""
|
||||
text = re.sub('(.)([A-Z][a-z]+)', r'\1-\2', text)
|
||||
text = re.sub('([a-z0-9])([A-Z])', r'\1-\2', text)
|
||||
return text.lower()
|
||||
|
||||
|
||||
def prepare_worker(
|
||||
main_workflow: type,
|
||||
other_workflows: Sequence[type],
|
||||
activities: Sequence[Any],
|
||||
temporal_client: Client,
|
||||
logger: Logger,
|
||||
) -> Worker:
|
||||
main_workflow_name = main_workflow.__name__.upper()
|
||||
|
||||
queue_name = f'{main_workflow_name.lower().replace("_", "-")}-queue'
|
||||
queue_name = f'{camel_to_kebab(main_workflow.__name__)}-queue'
|
||||
|
||||
local_workflow_parameters = {}
|
||||
|
||||
@@ -36,6 +49,8 @@ def prepare_worker(
|
||||
os.getenv(main_workflow_name + '_' + parameter[0], parameter[1])
|
||||
)
|
||||
|
||||
logger.info(f'Preparing worker for {main_workflow_name} with queue {queue_name}')
|
||||
|
||||
return Worker(
|
||||
temporal_client,
|
||||
task_queue=queue_name,
|
||||
|
||||
@@ -140,6 +140,7 @@ async def main():
|
||||
activities.write_metrics,
|
||||
activities.store_data_package,
|
||||
],
|
||||
logger=logger,
|
||||
),
|
||||
prepare_worker(
|
||||
temporal_client=temporal_client,
|
||||
@@ -154,6 +155,7 @@ async def main():
|
||||
activities.write_metrics,
|
||||
activities.store_data_package,
|
||||
],
|
||||
logger=logger,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
51
tests.ipynb
51
tests.ipynb
@@ -2,7 +2,7 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 2,
|
||||
"id": "9d16b24a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -38,7 +38,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 3,
|
||||
"id": "5e344fb0",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -103,12 +103,22 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from temporalio import client\n",
|
||||
"import datetime\n",
|
||||
"\n",
|
||||
"temporal_client = await client.Client.connect(\n",
|
||||
" target_host=\"localhost:7233\",\n",
|
||||
" namespace=\"scouter\"\n",
|
||||
")\n",
|
||||
")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"id": "45712d7a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"\n",
|
||||
"import datetime\n",
|
||||
"\n",
|
||||
"now = datetime.datetime.now()\n",
|
||||
"\n",
|
||||
@@ -124,6 +134,31 @@
|
||||
")\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "d065d0de",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"pi-web-api-scouter\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import re\n",
|
||||
"def camel_to_kebab(text: str) -> str:\n",
|
||||
" \"\"\"Convert camelCase or PascalCase to kebab-case.\"\"\"\n",
|
||||
" text = re.sub('(.)([A-Z][a-z]+)', r'\\1-\\2', text)\n",
|
||||
" text = re.sub('([a-z0-9])([A-Z])', r'\\1-\\2', text)\n",
|
||||
" return text.lower()\n",
|
||||
"\n",
|
||||
"print(camel_to_kebab('PiWebApiScouter'))\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
@@ -133,7 +168,15 @@
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.14"
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user