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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ output/
# gocd generated output
gocd/templates/vendor/
gocd/generated-pipelines/

# uv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want uv.lock here long term - I think we should be using uv.lock but can do this for now.

uv.lock
15 changes: 12 additions & 3 deletions src/launchpad/worker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
logger = get_logger(__name__)


DEFAULT_HEALTH_CHECK_FILE_PATH = "/tmp/health"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there only one worker running per node?
Doing "launchpad-taskworker-{os.getpid()}" or something might be better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supposedly the K8s liveness probe needs a static path baked into the pod spec. A PID-based path would break it. And since each pod has its own isolated /tmp, there's no collision risk anyway



@dataclass
class WorkerConfig:
rpc_hosts: list[str]
concurrency: int
health_check_file_path: str


def get_worker_config() -> WorkerConfig:
Expand All @@ -34,16 +38,20 @@ def get_worker_config() -> WorkerConfig:
except ValueError:
raise ValueError(f"LAUNCHPAD_WORKER_CONCURRENCY must be a valid integer, got: {concurrency_str}")

return WorkerConfig(rpc_hosts=rpc_hosts, concurrency=concurrency)
health_check_file_path = os.getenv("LAUNCHPAD_WORKER_HEALTH_CHECK_FILE_PATH", DEFAULT_HEALTH_CHECK_FILE_PATH)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here also re maybe needing to include the pid/soem random number


return WorkerConfig(rpc_hosts=rpc_hosts, concurrency=concurrency, health_check_file_path=health_check_file_path)


def run_worker() -> None:
initialize_sentry_sdk()
config = get_worker_config()

logger.info(f"Starting TaskWorker (rpc_hosts={config.rpc_hosts}, concurrency={config.concurrency})")
logger.info(
f"Starting TaskWorker (rpc_hosts={config.rpc_hosts}, concurrency={config.concurrency}, "
f"health_check_file_path={config.health_check_file_path})"
)

# TODO: Should we explore setting health_check_file_path for K8s file-based liveness probes (TaskWorker has no HTTP server)
worker = TaskWorker(
app_module="launchpad.worker.app:app",
broker_hosts=config.rpc_hosts,
Expand All @@ -54,6 +62,7 @@ def run_worker() -> None:
rebalance_after=16,
processing_pool_name="launchpad",
process_type="forkserver",
health_check_file_path=config.health_check_file_path,
)

exitcode = worker.start()
Expand Down
20 changes: 18 additions & 2 deletions tests/unit/test_worker_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from launchpad.worker.config import WorkerConfig, get_worker_config
from launchpad.worker.config import DEFAULT_HEALTH_CHECK_FILE_PATH, WorkerConfig, get_worker_config


class TestGetWorkerConfig:
Expand All @@ -17,7 +17,23 @@ def test_valid_config(self):
},
):
config = get_worker_config()
assert config == WorkerConfig(rpc_hosts=["localhost:50051"], concurrency=8)
assert config == WorkerConfig(
rpc_hosts=["localhost:50051"],
concurrency=8,
health_check_file_path=DEFAULT_HEALTH_CHECK_FILE_PATH,
)

def test_custom_health_check_file_path(self):
with patch.dict(
os.environ,
{
"LAUNCHPAD_WORKER_RPC_HOST": "localhost:50051",
"LAUNCHPAD_WORKER_CONCURRENCY": "8",
"LAUNCHPAD_WORKER_HEALTH_CHECK_FILE_PATH": "/custom/health",
},
):
config = get_worker_config()
assert config.health_check_file_path == "/custom/health"

def test_comma_separated_hosts(self):
with patch.dict(
Expand Down
Loading