Skip to content

Commit 12c09da

Browse files
author
Dmitriy Astapkovich
committed
fix: update monitoring
1 parent f493b32 commit 12c09da

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name = "temporal-boost"
1010
packages = [{include = "temporal_boost"}]
1111
readme = "README.md"
1212
repository = "https://github.com/northpowered/temporal-boost"
13-
version = "1.2.0"
13+
version = "2.0.0-rc.1"
1414

1515
classifiers = [
1616
"Programming Language :: Python :: 3",

temporal_boost/cli/runner.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import importlib
22
import logging
3+
import os
4+
import tempfile
35
from multiprocessing import Process
6+
from pathlib import Path
47
from typing import TYPE_CHECKING, Any
58

69
import typer
@@ -14,6 +17,28 @@
1417
cli = typer.Typer(help="CLI runner for BoostApp services")
1518

1619

20+
def setup_prometheus_multiproc_dir() -> None:
21+
prometheus_dir = os.getenv("PROMETHEUS_MULTIPROC_DIR")
22+
23+
if prometheus_dir:
24+
path = Path(prometheus_dir)
25+
if not path.exists():
26+
try:
27+
path.mkdir(parents=True, exist_ok=True)
28+
logger.info(f"Created prometheus multiprocess dir at {prometheus_dir}")
29+
except Exception as e:
30+
logger.warning(f"Cannot create prometheus multiprocess dir '{prometheus_dir}': {e}")
31+
del os.environ["PROMETHEUS_MULTIPROC_DIR"]
32+
logger.warning("Unset PROMETHEUS_MULTIPROC_DIR due to errors")
33+
else:
34+
try:
35+
temp_dir = tempfile.mkdtemp(prefix="prometheus_multiproc_")
36+
os.environ["PROMETHEUS_MULTIPROC_DIR"] = temp_dir
37+
logger.info(f"Set temporary PROMETHEUS_MULTIPROC_DIR at {temp_dir}")
38+
except Exception as e:
39+
logger.warning(f"Failed to set temporary PROMETHEUS_MULTIPROC_DIR: {e}")
40+
41+
1742
def _import_app_object(app_path: str) -> Any:
1843
if ":" not in app_path:
1944
raise typer.BadParameter("App path must be in format 'module.submodule:app'")
@@ -31,11 +56,14 @@ def _run_single(app_path: str, run_args: list[str]) -> None:
3156

3257

3358
def _run_multiprocess(app_path: str, processes: int, run_args: list[str]) -> None:
59+
setup_prometheus_multiproc_dir()
60+
3461
process_list: list[Process] = []
3562
for index in range(processes):
3663
process = Process(target=_run_single, args=(app_path, run_args), name=f"worker-{index}")
3764
process_list.append(process)
3865
process.start()
66+
3967
for process in process_list:
4068
process.join()
4169

0 commit comments

Comments
 (0)