perago.prepare_worker_runtime#

perago.prepare_worker_runtime(*, config, module_target, env)[源代码]#

Prepare local runtime state for one worker process.

The worker process calls this before polling Conductor. Preparation resolves the worker id and configures Loguru to write serialized JSONL logs under the configured log root.

Parameters:
configRuntimeConfig

Worker-local runtime configuration containing workspace and log roots, log rotation settings, and the worker id prefix.

module_targetstr

Python import path of the single task module served by this worker. It is used when a worker id must be derived from the module target.

envdict of str to str

Environment mapping visible to the worker process. PERAGO_WORKER_ID is used when present.

Returns:
WorkerRuntime

Prepared worker id, log file path, and swept attempt workspaces.

参数:
返回类型:

WorkerRuntime

参见

WorkerRuntime

Prepared runtime value returned by this function.

load_runtime_config

Load the RuntimeConfig argument from local env.

Notes

This function mutates process logging configuration by replacing the current Loguru sinks with the worker JSONL file sink.

Examples

>>> from datetime import timedelta
>>> config = RuntimeConfig(
...     workspace_root=Path("/tmp/perago/workspaces"),
...     log_root=Path("/tmp/perago/logs"),
...     log_file_max_size=1048576,
...     log_retention=timedelta(days=1),
...     worker_id_prefix="featuresBuild",
... )
>>> runtime = prepare_worker_runtime(
...     config=config,
...     module_target="app.workers.features_build",
...     env={"PERAGO_WORKER_ID": "featuresBuild0001"},
... )
>>> runtime.worker_id
'featuresBuild0001'