pz-cli 5.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pz_cli-5.0.0.dist-info/METADATA +51 -0
- pz_cli-5.0.0.dist-info/RECORD +399 -0
- pz_cli-5.0.0.dist-info/WHEEL +4 -0
- pz_cli-5.0.0.dist-info/entry_points.txt +5 -0
- pz_core/__init__.py +64 -0
- pz_core/__main__.py +7 -0
- pz_core/app.py +45 -0
- pz_core/assembly/__init__.py +17 -0
- pz_core/assembly/app_discovery.py +1240 -0
- pz_core/assembly/apps/__init__.py +25 -0
- pz_core/assembly/apps/compiler.py +824 -0
- pz_core/assembly/apps/providers.py +188 -0
- pz_core/assembly/cli/__init__.py +9 -0
- pz_core/assembly/cli/compiler.py +166 -0
- pz_core/assembly/diagnostics/__init__.py +21 -0
- pz_core/assembly/diagnostics/checks.py +257 -0
- pz_core/assembly/diagnostics/dev_sources.py +569 -0
- pz_core/assembly/events/__init__.py +5 -0
- pz_core/assembly/events/compiler.py +219 -0
- pz_core/assembly/extensions/__init__.py +5 -0
- pz_core/assembly/extensions/compiler.py +696 -0
- pz_core/assembly/infra/__init__.py +6 -0
- pz_core/assembly/infra/compiler.py +272 -0
- pz_core/assembly/lifecycle/__init__.py +5 -0
- pz_core/assembly/lifecycle/compiler.py +95 -0
- pz_core/assembly/middlewares/__init__.py +19 -0
- pz_core/assembly/middlewares/compiler.py +508 -0
- pz_core/assembly/project/__init__.py +7 -0
- pz_core/assembly/project/compiler.py +9 -0
- pz_core/assembly/project/context.py +17 -0
- pz_core/assembly/project/discovery.py +227 -0
- pz_core/assembly/resources/__init__.py +19 -0
- pz_core/assembly/resources/compiler.py +310 -0
- pz_core/assembly/resources/settings.py +129 -0
- pz_core/assembly/routes/__init__.py +7 -0
- pz_core/assembly/routes/compiler.py +400 -0
- pz_core/assembly/runtime_manifests/__init__.py +13 -0
- pz_core/assembly/runtime_manifests/compiler.py +159 -0
- pz_core/assembly/settings/__init__.py +17 -0
- pz_core/assembly/settings/compiler.py +786 -0
- pz_core/assembly/settings/host_project_overrides.py +82 -0
- pz_core/assembly/settings/host_runtime_endpoint.py +207 -0
- pz_core/authoring/__init__.py +79 -0
- pz_core/authoring/app_init_service.py +946 -0
- pz_core/authoring/app_versions.py +814 -0
- pz_core/authoring/cli.py +192 -0
- pz_core/authoring/commands.py +1810 -0
- pz_core/authoring/conflicts.py +180 -0
- pz_core/authoring/dev_bindings.py +916 -0
- pz_core/authoring/dev_git.py +1087 -0
- pz_core/authoring/dev_import.py +1061 -0
- pz_core/authoring/dev_manifest.py +522 -0
- pz_core/authoring/dev_sources.py +1638 -0
- pz_core/authoring/env_cli.py +454 -0
- pz_core/authoring/files.py +109 -0
- pz_core/authoring/ide_projection.py +1129 -0
- pz_core/authoring/naming.py +58 -0
- pz_core/authoring/official_dev_sources.py +432 -0
- pz_core/authoring/official_sources.json +156 -0
- pz_core/authoring/orchestration_service.py +558 -0
- pz_core/authoring/project_default.jsonc +53 -0
- pz_core/authoring/project_defaults.py +88 -0
- pz_core/authoring/project_metadata_service.py +199 -0
- pz_core/authoring/project_settings_checks.py +51 -0
- pz_core/authoring/project_settings_cli.py +299 -0
- pz_core/authoring/project_settings_service.py +1700 -0
- pz_core/authoring/project_state.py +399 -0
- pz_core/authoring/publish_git.py +423 -0
- pz_core/authoring/publish_lock.py +188 -0
- pz_core/authoring/publish_source.py +195 -0
- pz_core/authoring/release.py +1382 -0
- pz_core/authoring/repo_keys.py +29 -0
- pz_core/authoring/root_cli.py +28 -0
- pz_core/authoring/scaffold_service.py +325 -0
- pz_core/authoring/sync_service.py +787 -0
- pz_core/authoring/templates/app/__init__.py +1 -0
- pz_core/authoring/templates/app/api.py +25 -0
- pz_core/authoring/templates/app/apps.py +31 -0
- pz_core/authoring/templates/app/auth_package_init.py +14 -0
- pz_core/authoring/templates/app/auth_readme.py +29 -0
- pz_core/authoring/templates/app/configs_package_init.py +14 -0
- pz_core/authoring/templates/app/default_env.py +18 -0
- pz_core/authoring/templates/app/default_jsonc.py +25 -0
- pz_core/authoring/templates/app/locales_readme.py +25 -0
- pz_core/authoring/templates/app/migrations_readme.py +19 -0
- pz_core/authoring/templates/app/models.py +14 -0
- pz_core/authoring/templates/app/package_init.py +8 -0
- pz_core/authoring/templates/app/pages_base.py +161 -0
- pz_core/authoring/templates/app/pages_readme.py +25 -0
- pz_core/authoring/templates/app/public.py +31 -0
- pz_core/authoring/templates/app/pyproject.py +77 -0
- pz_core/authoring/templates/app/readme.py +74 -0
- pz_core/authoring/templates/app/settings.py +46 -0
- pz_core/authoring/templates/app/static_app_js.py +24 -0
- pz_core/authoring/templates/app/static_readme.py +31 -0
- pz_core/authoring/templates/app/template_config_page.py +23 -0
- pz_core/authoring/templates/app/template_index_html.py +28 -0
- pz_core/authoring/templates/app/templates_readme.py +32 -0
- pz_core/authoring/templates/app/urls.py +36 -0
- pz_core/authoring/templates/app/views.py +36 -0
- pz_core/authoring/templates/project/__init__.py +1 -0
- pz_core/authoring/templates/project/agents.py +51 -0
- pz_core/authoring/templates/project/apps_container_readme.py +37 -0
- pz_core/authoring/templates/project/main_py.py +59 -0
- pz_core/authoring/templates/project/project_env.py +19 -0
- pz_core/authoring/templates/project/pyproject.py +26 -0
- pz_core/authoring/templates/project/pz_env_env.py +65 -0
- pz_core/authoring/templates/project/pz_env_jsonc.py +69 -0
- pz_core/authoring/templates/project/pz_jsonc.py +12 -0
- pz_core/authoring/templates/project/readme.py +94 -0
- pz_core/authoring/templates/project/root_gitkeep.py +8 -0
- pz_core/authoring/templates/shared/__init__.py +5 -0
- pz_core/authoring/templates/shared/text.py +10 -0
- pz_core/authoring/venv_service.py +87 -0
- pz_core/authoring/workspace.py +167 -0
- pz_core/cli.py +291 -0
- pz_core/cli_options.py +74 -0
- pz_core/core/__init__.py +3 -0
- pz_core/core/errors/__init__.py +5 -0
- pz_core/core/errors/models.py +117 -0
- pz_core/core/events/__init__.py +5 -0
- pz_core/core/events/registry.py +54 -0
- pz_core/core/extensions/__init__.py +51 -0
- pz_core/core/extensions/registry.py +790 -0
- pz_core/core/health/__init__.py +6 -0
- pz_core/core/health/contracts.py +10 -0
- pz_core/core/middlewares/__init__.py +6 -0
- pz_core/core/middlewares/models.py +24 -0
- pz_core/core/routing/__init__.py +5 -0
- pz_core/core/routing/models.py +21 -0
- pz_core/core/settings_contracts.py +25 -0
- pz_core/docs/README.md +20 -0
- pz_core/docs/distribution-README.md +438 -0
- pz_core/docs/pz/345/221/275/344/273/244/346/200/273/350/247/210.md +1011 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/00-pz/346/236/266/346/236/204/346/200/273/347/272/262.md +240 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/01-/347/233/256/345/275/225/344/270/216/345/210/206/345/261/202/350/247/204/350/214/203.md +216 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/02-/345/214/205/344/270/216/345/210/206/345/217/221/350/247/204/350/214/203.md +403 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/03-App/346/234/200/345/260/217/345/255/220/345/214/205/350/247/204/350/214/203.md +571 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/04-Settings/344/270/216/351/205/215/347/275/256/350/247/204/350/214/203.md +1177 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/05-/350/265/204/346/272/220/344/270/216/350/277/220/350/241/214/347/233/256/345/275/225/350/247/204/350/214/203.md +575 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/06-/346/225/260/346/215/256/345/272/223/344/270/216/345/217/257/351/200/211/345/237/272/347/241/200/350/256/276/346/226/275/350/247/204/350/214/203.md +499 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/07-App/346/233/277/346/215/242/350/247/204/350/214/203.md +206 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/08-/345/271/263/345/217/260/347/272/247App/344/270/216/350/277/220/350/241/214/346/227/266/345/215/225/344/276/213/350/247/204/350/214/203.md +445 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/09-CLI/344/270/216Worker/345/205/245/345/217/243/350/247/204/350/214/203.md +950 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/10-/346/265/213/350/257/225/344/270/216/345/245/221/347/272/246/350/247/204/350/214/203.md +1001 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/11-/344/273/223/345/272/223/347/234/237/347/233/270/346/272/220/345/234/260/345/233/276.md +102 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/12-/346/236/204/345/273/272/344/270/216/345/217/221/345/270/203/346/243/200/346/237/245/346/270/205/345/215/225.md +171 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/13-/346/255/243/345/274/217Facade/346/200/273/350/241/250.md +402 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/14-/345/210/206/345/261/202/344/270/216/346/211/251/345/261/225/350/247/204/350/214/203.md +550 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/15-/345/255/220/345/214/205/345/274/200/345/217/221/344/275/277/347/224/250/346/211/213/345/206/214.md +1004 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/16-/346/211/251/345/261/225/347/202/271/346/255/243/345/274/217/345/215/217/350/256/256/346/270/205/345/215/225.md +352 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/17-pz.protocols.v1/346/255/243/345/274/217/345/215/217/350/256/256.md +266 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/18-/346/211/251/345/261/225/347/202/271/345/206/262/347/252/201/350/243/201/345/206/263/346/200/273/350/241/250.md +131 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/19-/351/224/231/350/257/257/347/240/201/344/270/216/350/257/212/346/226/255/345/215/217/350/256/256.md +176 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/20-/347/247/201/346/234/211/345/214/205/344/273/223/344/270/216/347/273/237/344/270/200/350/256/244/350/257/201/351/203/250/347/275/262/350/247/204/350/214/203.md +243 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/21-contrib/347/272/246/345/256/232/344/270/216Provider/346/216/245/345/205/245/350/247/204/350/214/203.md +365 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/22-/345/244/232/345/233/275/350/257/255/350/250/200/350/265/204/346/272/220/346/262/273/347/220/206/344/270/216/346/214/211/351/234/200/345/212/240/350/275/275/350/247/204/350/214/203.md +912 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/23-/351/246/226/345/261/217/345/261/225/347/244/272/344/270/216/351/246/226/345/270/247/347/250/263/345/256/232/350/247/204/350/214/203.md +269 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/24-pz/345/220/257/345/212/250/344/270/216/350/277/220/350/241/214/346/227/266/347/274/226/350/257/221/346/265/201/347/250/213.md +245 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/25-/351/235/242/345/220/221/345/257/271/350/261/241/345/274/200/345/217/221/350/247/204/350/214/203.md +300 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/README.md +98 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/00-legacy_core/346/240/207/345/207/206pip/345/214/205/345/214/226/351/207/215/346/236/204/346/200/273/347/272/262.md +1073 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/01-/347/233/256/345/275/225/344/270/216/345/210/206/345/261/202/351/207/215/346/236/204/346/211/247/350/241/214/346/226/271/346/241/210.md +224 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/02-/345/214/205/344/270/216/345/210/206/345/217/221/350/247/204/350/214/203-/345/220/253/345/216/206/345/217/262/345/217/243/345/276/204.md +671 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/13-/344/270/200/346/254/241/346/200/247/345/256/236/346/226/275/346/270/205/345/215/225.md +387 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/14-/345/255/220/345/214/205/351/200/202/351/205/215/346/224/271/351/200/240/346/270/205/345/215/225.md +592 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/15-infra/350/243/201/345/211/252/344/270/216/350/220/275/344/275/215/346/270/205/345/215/225.md +81 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/19-core/345/215/225/344/270/200/346/255/243/345/274/217/346/226/271/346/241/210/346/224/266/346/225/233/346/211/247/350/241/214/346/270/205/345/215/225.md +161 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/25-/345/215/217/350/256/256/345/210/260/346/272/220/347/240/201/345/267/256/350/267/235/346/270/205/345/215/225.md +377 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/26-cutover/345/256/214/345/267/245/346/243/200/346/237/245/346/270/205/345/215/225.md +117 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/29-/345/244/232/345/233/275/350/257/255/350/250/200/350/265/204/346/272/220/346/262/273/347/220/206/344/270/216/346/214/211/351/234/200/345/212/240/350/275/275/350/247/204/350/214/203-/345/220/253/350/277/201/347/247/273/347/255/226/347/225/245.md +956 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/99-/350/265/204/346/272/220/346/224/266/345/217/243/345/220/216/347/273/255TODO.md +84 -0
- pz_core/docs//345/217/221/347/211/210/345/211/215/346/270/205/345/215/225-4.0.11.md +84 -0
- pz_core/docs//346/226/260/346/211/213/346/214/207/345/215/227.md +422 -0
- pz_core/infra/__init__.py +17 -0
- pz_core/infra/db/__init__.py +23 -0
- pz_core/infra/db/contracts.py +73 -0
- pz_core/infra/health/__init__.py +5 -0
- pz_core/infra/health/contracts.py +8 -0
- pz_core/infra/kv/__init__.py +5 -0
- pz_core/infra/kv/contracts.py +17 -0
- pz_core/infra/observability/__init__.py +23 -0
- pz_core/infra/observability/contracts.py +142 -0
- pz_core/infra/resilience/__init__.py +5 -0
- pz_core/infra/resilience/contracts.py +17 -0
- pz_core/infra/resources/__init__.py +5 -0
- pz_core/infra/resources/contracts.py +16 -0
- pz_core/infra/settings/__init__.py +17 -0
- pz_core/infra/settings/models.py +81 -0
- pz_core/infra/storage/__init__.py +5 -0
- pz_core/infra/storage/ports.py +27 -0
- pz_core/project_root_commands.py +282 -0
- pz_core/project_runtime_cli.py +344 -0
- pz_core/project_sources.py +253 -0
- pz_core/pz_launcher.py +209 -0
- pz_core/root_cli.py +70 -0
- pz_core/runtime/__init__.py +229 -0
- pz_core/runtime/access.py +86 -0
- pz_core/runtime/adapters/__init__.py +5 -0
- pz_core/runtime/adapters/base.py +18 -0
- pz_core/runtime/asyncio_bridge.py +18 -0
- pz_core/runtime/bindings/__init__.py +5 -0
- pz_core/runtime/bindings/container.py +50 -0
- pz_core/runtime/cli/__init__.py +5 -0
- pz_core/runtime/cli/_args.py +67 -0
- pz_core/runtime/cli/app_commands.py +417 -0
- pz_core/runtime/cli/check.py +214 -0
- pz_core/runtime/cli/db.py +297 -0
- pz_core/runtime/cli/main.py +89 -0
- pz_core/runtime/cli/resources.py +280 -0
- pz_core/runtime/discovery.py +23 -0
- pz_core/runtime/environment_integrity.py +157 -0
- pz_core/runtime/errors.py +5 -0
- pz_core/runtime/events.py +87 -0
- pz_core/runtime/facades/__init__.py +38 -0
- pz_core/runtime/facades/_capabilities.py +46 -0
- pz_core/runtime/facades/cache.py +103 -0
- pz_core/runtime/facades/database.py +71 -0
- pz_core/runtime/facades/events.py +380 -0
- pz_core/runtime/facades/health.py +101 -0
- pz_core/runtime/facades/mail.py +121 -0
- pz_core/runtime/facades/observability.py +102 -0
- pz_core/runtime/facades/providers.py +75 -0
- pz_core/runtime/facades/resources.py +52 -0
- pz_core/runtime/facades/storage.py +296 -0
- pz_core/runtime/health/__init__.py +5 -0
- pz_core/runtime/health/service.py +102 -0
- pz_core/runtime/host.py +188 -0
- pz_core/runtime/host_runner.py +282 -0
- pz_core/runtime/http/__init__.py +20 -0
- pz_core/runtime/http/app.py +576 -0
- pz_core/runtime/http_timing.py +173 -0
- pz_core/runtime/invocation.py +29 -0
- pz_core/runtime/json_safe.py +47 -0
- pz_core/runtime/lifecycle/__init__.py +25 -0
- pz_core/runtime/lifecycle/manager.py +533 -0
- pz_core/runtime/plan.py +214 -0
- pz_core/runtime/plan_context.py +33 -0
- pz_core/runtime/plan_snapshot.py +177 -0
- pz_core/runtime/registries/__init__.py +27 -0
- pz_core/runtime/registries/capabilities.py +101 -0
- pz_core/runtime/registries/providers.py +396 -0
- pz_core/runtime/resource_assets.py +344 -0
- pz_core/runtime/run_cli.py +211 -0
- pz_core/runtime/settings.py +888 -0
- pz_core/runtime/worker/__init__.py +21 -0
- pz_core/runtime/worker/engine.py +921 -0
- pz_core/runtime/worker/runtime.py +25 -0
- pz_core/testing/__init__.py +15 -0
- pz_core/testing/doc_route_contracts.py +305 -0
- pz_core/utils/__init__.py +44 -0
- pz_core/utils/env.py +65 -0
- pz_core/utils/project_jsonc/__init__.py +29 -0
- pz_core/utils/project_jsonc/document.py +420 -0
- pz_core/utils/project_settings.py +99 -0
- pz_foundation/__init__.py +50 -0
- pz_foundation/_contracts.py +81 -0
- pz_foundation/_errors.py +34 -0
- pz_foundation/api.py +14 -0
- pz_foundation/apps.py +127 -0
- pz_foundation/auth/__init__.py +1 -0
- pz_foundation/cache_control.py +233 -0
- pz_foundation/cli/__init__.py +2 -0
- pz_foundation/cli/workers.py +565 -0
- pz_foundation/configs/__init__.py +0 -0
- pz_foundation/configs/default.env +15 -0
- pz_foundation/configs/default.jsonc +452 -0
- pz_foundation/db/__init__.py +94 -0
- pz_foundation/db/aerich_executor.py +664 -0
- pz_foundation/db/config.py +358 -0
- pz_foundation/db/connection_manager.py +689 -0
- pz_foundation/db/connection_probe.py +204 -0
- pz_foundation/db/database.py +1291 -0
- pz_foundation/db/deps.py +47 -0
- pz_foundation/db/lifecycle_status.py +85 -0
- pz_foundation/db/migrations.py +477 -0
- pz_foundation/db/mysql.py +57 -0
- pz_foundation/db/postgresql.py +409 -0
- pz_foundation/db/production_pool_fallback.py +143 -0
- pz_foundation/db/public.py +45 -0
- pz_foundation/db/session.py +369 -0
- pz_foundation/db/sqlite.py +15 -0
- pz_foundation/db/tortoise_manager.py +724 -0
- pz_foundation/db/tortoise_psycopg.py +148 -0
- pz_foundation/docs/README.md +18 -0
- pz_foundation/docs/distribution-README.md +319 -0
- pz_foundation/docs/infra/350/243/201/345/211/252/344/270/216/350/220/275/344/275/215/350/257/264/346/230/216.md +39 -0
- pz_foundation/docs//345/205/254/345/274/200/345/205/215/350/264/271/346/216/245/345/217/243/351/230/262/346/273/245/347/224/250/344/270/216/344/272/272/346/234/272/346/240/241/351/252/214.md +680 -0
- pz_foundation/docs//350/256/276/350/256/241/346/226/207/346/241/243.md +288 -0
- pz_foundation/docs//350/267/257/347/224/261/344/270/216URL/345/244/204/347/220/206/350/247/204/350/214/203.md +119 -0
- pz_foundation/health.py +105 -0
- pz_foundation/host/__init__.py +11 -0
- pz_foundation/host/builder.py +34 -0
- pz_foundation/host/cache_runtime.py +44 -0
- pz_foundation/host/db/__init__.py +17 -0
- pz_foundation/host/db/aerich_config.py +36 -0
- pz_foundation/host/db/config.py +106 -0
- pz_foundation/host/db/connection_manager.py +48 -0
- pz_foundation/host/db/deps.py +5 -0
- pz_foundation/host/db/orm_retry_patch.py +566 -0
- pz_foundation/host/db/request_adapter.py +325 -0
- pz_foundation/host/db/router.py +28 -0
- pz_foundation/host/db/session.py +284 -0
- pz_foundation/host/db/tortoise_manager.py +10 -0
- pz_foundation/host/idempotency.py +132 -0
- pz_foundation/host/lifespan.py +247 -0
- pz_foundation/host/redis_runtime.py +100 -0
- pz_foundation/host/web.py +790 -0
- pz_foundation/infra_provider.py +236 -0
- pz_foundation/kv/__init__.py +25 -0
- pz_foundation/kv/cache.py +1166 -0
- pz_foundation/kv/deps.py +84 -0
- pz_foundation/kv/public.py +25 -0
- pz_foundation/kv/redis_manager.py +1531 -0
- pz_foundation/lazy_exports.py +43 -0
- pz_foundation/lazy_imports.py +124 -0
- pz_foundation/lifecycle.py +392 -0
- pz_foundation/managed_workers.py +1117 -0
- pz_foundation/middlewares/__init__.py +26 -0
- pz_foundation/middlewares/_settings.py +250 -0
- pz_foundation/middlewares/analytics.py +124 -0
- pz_foundation/middlewares/cache_control.py +156 -0
- pz_foundation/middlewares/compression.py +202 -0
- pz_foundation/middlewares/cors.py +62 -0
- pz_foundation/middlewares/geo_country.py +44 -0
- pz_foundation/middlewares/inner_router.py +50 -0
- pz_foundation/middlewares/rate_limited/__init__.py +3 -0
- pz_foundation/middlewares/rate_limited/key_limiter.py +115 -0
- pz_foundation/middlewares/request_logging.py +104 -0
- pz_foundation/middlewares/route_owner.py +309 -0
- pz_foundation/middlewares/security_csrf.py +44 -0
- pz_foundation/middlewares/security_headers/__init__.py +4 -0
- pz_foundation/middlewares/security_headers/conflicts.py +44 -0
- pz_foundation/middlewares/security_headers/csp_nonce.py +200 -0
- pz_foundation/middlewares/security_headers/security_headers.py +44 -0
- pz_foundation/migrations/__init__.py +1 -0
- pz_foundation/migrations/pz_foundation/__init__.py +1 -0
- pz_foundation/models.py +22 -0
- pz_foundation/notifications/__init__.py +23 -0
- pz_foundation/notifications/email.py +542 -0
- pz_foundation/notifications/public.py +31 -0
- pz_foundation/observability/__init__.py +71 -0
- pz_foundation/observability/http.py +34 -0
- pz_foundation/observability/logger/__init__.py +49 -0
- pz_foundation/observability/logger/_bot_settings.py +126 -0
- pz_foundation/observability/logger/bot_message.py +592 -0
- pz_foundation/observability/logger/core.py +385 -0
- pz_foundation/observability/logger/delivery_audit.py +84 -0
- pz_foundation/observability/logger/feishu_bot.py +199 -0
- pz_foundation/observability/logger/telegram_bot.py +194 -0
- pz_foundation/observability/metrics.py +365 -0
- pz_foundation/observability/runtime.py +68 -0
- pz_foundation/public.py +405 -0
- pz_foundation/resources/__init__.py +12 -0
- pz_foundation/resources/builder.py +900 -0
- pz_foundation/resources/images.py +363 -0
- pz_foundation/root_cli.py +20 -0
- pz_foundation/routing/__init__.py +203 -0
- pz_foundation/routing/canonical.py +486 -0
- pz_foundation/routing/convertors.py +82 -0
- pz_foundation/routing/declarations.py +843 -0
- pz_foundation/routing/exports.py +148 -0
- pz_foundation/routing/loaders.py +138 -0
- pz_foundation/routing/manifest.py +215 -0
- pz_foundation/routing/manifest_provider.py +47 -0
- pz_foundation/routing/mounts.py +101 -0
- pz_foundation/routing/ordering.py +172 -0
- pz_foundation/routing/registry.py +133 -0
- pz_foundation/routing/utils.py +28 -0
- pz_foundation/runtime.py +234 -0
- pz_foundation/settings.py +253 -0
- pz_foundation/settings_normalization.py +130 -0
- pz_foundation/storage/__init__.py +25 -0
- pz_foundation/storage/local.py +209 -0
- pz_foundation/storage/public.py +106 -0
- pz_foundation/storage/s3.py +116 -0
- pz_foundation/storage/service.py +234 -0
- pz_foundation/urls.py +19 -0
- pz_foundation/utils/__init__.py +6 -0
- pz_foundation/utils/merge.py +160 -0
- pz_foundation/worker_replicas.py +55 -0
- pz_settings_center/__init__.py +5 -0
- pz_settings_center/api/__init__.py +5 -0
- pz_settings_center/api/runtime_overrides.py +360 -0
- pz_settings_center/apps.py +28 -0
- pz_settings_center/configs/__init__.py +0 -0
- pz_settings_center/configs/default.env +2 -0
- pz_settings_center/configs/default.jsonc +1 -0
- pz_settings_center/docs/01-settings_center/350/203/275/345/212/233/350/276/271/347/225/214.md +124 -0
- pz_settings_center/docs/README.md +12 -0
- pz_settings_center/docs/distribution-README.md +150 -0
- pz_settings_center/docs//350/256/276/350/256/241/346/226/207/346/241/243.md +48 -0
- pz_settings_center/integration_payload.py +18 -0
- pz_settings_center/project_helpers.py +405 -0
- pz_settings_center/public.py +139 -0
- pz_settings_center/routing_helpers.py +73 -0
- pz_settings_center/runtime_override_provider.py +61 -0
- pz_settings_center/typed_settings.py +324 -0
- pz_settings_center/urls.py +9 -0
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
import time
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from pz_core.core.extensions import CliToolSpec
|
|
11
|
+
from pz_core.runtime import compile_runtime_plan
|
|
12
|
+
from pz_core.runtime.errors import as_pz_error
|
|
13
|
+
from pz_foundation.managed_workers import (
|
|
14
|
+
ManagedWorkerSupervisor,
|
|
15
|
+
_is_process_alive,
|
|
16
|
+
managed_worker_supervisor_signature,
|
|
17
|
+
managed_worker_subprocess_env,
|
|
18
|
+
managed_worker_status_payload,
|
|
19
|
+
resolve_project_pz_executable,
|
|
20
|
+
stop_managed_workers,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _coerce_bool(value: object, default: bool) -> bool:
|
|
25
|
+
if isinstance(value, bool):
|
|
26
|
+
return value
|
|
27
|
+
if value is None:
|
|
28
|
+
return bool(default)
|
|
29
|
+
if isinstance(value, str):
|
|
30
|
+
text = value.strip().lower()
|
|
31
|
+
if not text:
|
|
32
|
+
return bool(default)
|
|
33
|
+
if text in {"1", "true", "yes", "on"}:
|
|
34
|
+
return True
|
|
35
|
+
if text in {"0", "false", "no", "off"}:
|
|
36
|
+
return False
|
|
37
|
+
return bool(value)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _coerce_positive_int(value: object) -> int | None:
|
|
41
|
+
if value is None:
|
|
42
|
+
return None
|
|
43
|
+
try:
|
|
44
|
+
parsed = int(value)
|
|
45
|
+
except (TypeError, ValueError):
|
|
46
|
+
return None
|
|
47
|
+
return parsed if parsed > 0 else None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _force_restart_on_host_start(resolved_plan) -> bool: # noqa: ANN001
|
|
51
|
+
try:
|
|
52
|
+
settings = getattr(getattr(resolved_plan, "settings", None), "app_settings", None)
|
|
53
|
+
payload = settings("pz_foundation") if callable(settings) else {}
|
|
54
|
+
except Exception:
|
|
55
|
+
return True
|
|
56
|
+
managed_workers = payload.get("managed_workers") if isinstance(payload, dict) else {}
|
|
57
|
+
if not isinstance(managed_workers, dict):
|
|
58
|
+
return True
|
|
59
|
+
return _coerce_bool(managed_workers.get("force_restart_on_host_start"), True)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
63
|
+
parser = argparse.ArgumentParser(
|
|
64
|
+
prog="pz workers",
|
|
65
|
+
description=(
|
|
66
|
+
"Manage detached managed workers declared by the current RuntimePlan.\n\n"
|
|
67
|
+
"Without names and without --all, commands target auto-start workers only. "
|
|
68
|
+
"Names match worker name, extension id, or <app_id>.<tool_name>."
|
|
69
|
+
),
|
|
70
|
+
epilog=(
|
|
71
|
+
"Examples:\n"
|
|
72
|
+
" pz workers list\n"
|
|
73
|
+
" pz workers status --json\n"
|
|
74
|
+
" pz workers restart mission_carrier.task_center_worker\n"
|
|
75
|
+
" pz workers restart --all --start-timeout 90\n"
|
|
76
|
+
" pz workers run --detach --owner-pid 12345"
|
|
77
|
+
),
|
|
78
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
79
|
+
)
|
|
80
|
+
parser.add_argument(
|
|
81
|
+
"--project-dir",
|
|
82
|
+
dest="project_dir",
|
|
83
|
+
default=None,
|
|
84
|
+
help="Project root containing pz.jsonc. Defaults to the discovered current project.",
|
|
85
|
+
)
|
|
86
|
+
parser.add_argument(
|
|
87
|
+
"--json",
|
|
88
|
+
action="store_true",
|
|
89
|
+
dest="json_output",
|
|
90
|
+
default=argparse.SUPPRESS,
|
|
91
|
+
help="Emit machine-readable JSON for commands that produce status payloads.",
|
|
92
|
+
)
|
|
93
|
+
subparsers = parser.add_subparsers(dest="command", required=False)
|
|
94
|
+
|
|
95
|
+
list_parser = subparsers.add_parser(
|
|
96
|
+
"list",
|
|
97
|
+
help="List managed worker targets and runtime state.",
|
|
98
|
+
description="List managed worker targets and runtime state for the current project.",
|
|
99
|
+
)
|
|
100
|
+
_add_worker_selection_arguments(list_parser)
|
|
101
|
+
_add_json_argument(list_parser)
|
|
102
|
+
|
|
103
|
+
status_parser = subparsers.add_parser(
|
|
104
|
+
"status",
|
|
105
|
+
help="Show the same managed worker status projection as list.",
|
|
106
|
+
description="Show the managed worker status projection for scripts and operators.",
|
|
107
|
+
)
|
|
108
|
+
_add_worker_selection_arguments(status_parser)
|
|
109
|
+
_add_json_argument(status_parser)
|
|
110
|
+
|
|
111
|
+
run_parser = subparsers.add_parser(
|
|
112
|
+
"run",
|
|
113
|
+
help="Run the managed worker supervisor loop.",
|
|
114
|
+
description=(
|
|
115
|
+
"Run the managed worker supervisor. This is the low-level entry used by "
|
|
116
|
+
"pz run and restart; day-to-day operator use should prefer restart/status/stop."
|
|
117
|
+
),
|
|
118
|
+
)
|
|
119
|
+
_add_worker_selection_arguments(run_parser)
|
|
120
|
+
run_parser.add_argument(
|
|
121
|
+
"--poll-interval",
|
|
122
|
+
type=float,
|
|
123
|
+
default=1.0,
|
|
124
|
+
help="Seconds between supervisor reconciliation loops. Default: 1.0.",
|
|
125
|
+
)
|
|
126
|
+
run_parser.add_argument(
|
|
127
|
+
"--owner-pid",
|
|
128
|
+
type=int,
|
|
129
|
+
default=None,
|
|
130
|
+
help="Optional parent host PID. The detached supervisor stops when this owner exits.",
|
|
131
|
+
)
|
|
132
|
+
run_parser.add_argument(
|
|
133
|
+
"--detach",
|
|
134
|
+
action="store_true",
|
|
135
|
+
help="Start the supervisor as a detached background process and return immediately.",
|
|
136
|
+
)
|
|
137
|
+
run_parser.add_argument(
|
|
138
|
+
"--force-restart",
|
|
139
|
+
action="store_true",
|
|
140
|
+
default=argparse.SUPPRESS,
|
|
141
|
+
help="Stop any matching existing supervisor/workers before starting the detached supervisor.",
|
|
142
|
+
)
|
|
143
|
+
run_parser.add_argument(
|
|
144
|
+
"--no-force-restart",
|
|
145
|
+
action="store_false",
|
|
146
|
+
dest="force_restart",
|
|
147
|
+
default=argparse.SUPPRESS,
|
|
148
|
+
help="Keep a healthy matching supervisor when possible for this invocation.",
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
stop_parser = subparsers.add_parser(
|
|
152
|
+
"stop",
|
|
153
|
+
help="Stop the managed worker supervisor and matching workers.",
|
|
154
|
+
description="Stop the managed worker supervisor and matching worker replicas.",
|
|
155
|
+
)
|
|
156
|
+
_add_worker_selection_arguments(stop_parser)
|
|
157
|
+
stop_parser.add_argument(
|
|
158
|
+
"--timeout",
|
|
159
|
+
type=float,
|
|
160
|
+
default=15.0,
|
|
161
|
+
help="Seconds to wait for graceful shutdown before forceful termination. Default: 15.0.",
|
|
162
|
+
)
|
|
163
|
+
_add_json_argument(stop_parser)
|
|
164
|
+
|
|
165
|
+
restart_parser = subparsers.add_parser(
|
|
166
|
+
"restart",
|
|
167
|
+
help="Stop matching workers and launch a detached supervisor.",
|
|
168
|
+
description="Stop matching workers, launch a detached supervisor, then read back status.",
|
|
169
|
+
)
|
|
170
|
+
_add_worker_selection_arguments(restart_parser)
|
|
171
|
+
restart_parser.add_argument(
|
|
172
|
+
"--poll-interval",
|
|
173
|
+
type=float,
|
|
174
|
+
default=1.0,
|
|
175
|
+
help="Seconds between supervisor reconciliation loops after restart. Default: 1.0.",
|
|
176
|
+
)
|
|
177
|
+
restart_parser.add_argument(
|
|
178
|
+
"--owner-pid",
|
|
179
|
+
type=int,
|
|
180
|
+
default=None,
|
|
181
|
+
help="Optional parent host PID passed to the detached supervisor.",
|
|
182
|
+
)
|
|
183
|
+
restart_parser.add_argument(
|
|
184
|
+
"--timeout",
|
|
185
|
+
type=float,
|
|
186
|
+
default=15.0,
|
|
187
|
+
help="Seconds to wait while stopping existing workers. Default: 15.0.",
|
|
188
|
+
)
|
|
189
|
+
restart_parser.add_argument(
|
|
190
|
+
"--start-timeout",
|
|
191
|
+
type=float,
|
|
192
|
+
default=90.0,
|
|
193
|
+
help="Seconds to wait for restarted worker status before returning. Default: 90.0.",
|
|
194
|
+
)
|
|
195
|
+
_add_json_argument(restart_parser)
|
|
196
|
+
return parser
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _add_worker_selection_arguments(parser: argparse.ArgumentParser) -> None:
|
|
200
|
+
parser.add_argument(
|
|
201
|
+
"names",
|
|
202
|
+
nargs="*",
|
|
203
|
+
help="Optional worker selectors: worker name, extension id, or <app_id>.<tool_name>.",
|
|
204
|
+
)
|
|
205
|
+
parser.add_argument(
|
|
206
|
+
"--project-dir",
|
|
207
|
+
dest="project_dir",
|
|
208
|
+
default=None,
|
|
209
|
+
help="Project root containing pz.jsonc. Defaults to the discovered current project.",
|
|
210
|
+
)
|
|
211
|
+
parser.add_argument(
|
|
212
|
+
"--all",
|
|
213
|
+
action="store_true",
|
|
214
|
+
dest="include_non_autostart",
|
|
215
|
+
help="Include non-auto-start worker roles when no explicit names are provided.",
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def _add_json_argument(parser: argparse.ArgumentParser) -> None:
|
|
220
|
+
parser.add_argument(
|
|
221
|
+
"--json",
|
|
222
|
+
action="store_true",
|
|
223
|
+
dest="json_output",
|
|
224
|
+
default=argparse.SUPPRESS,
|
|
225
|
+
help="Emit machine-readable JSON.",
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def _emit(payload: dict[str, object], *, json_output: bool) -> int:
|
|
230
|
+
if json_output:
|
|
231
|
+
print(json.dumps(payload, ensure_ascii=True, sort_keys=True))
|
|
232
|
+
return 0
|
|
233
|
+
action = payload.get("action")
|
|
234
|
+
status = payload.get("status")
|
|
235
|
+
if action or status:
|
|
236
|
+
print(f"{action or 'managed_workers'} status={status or 'ok'}")
|
|
237
|
+
supervisor = payload.get("supervisor")
|
|
238
|
+
if isinstance(supervisor, dict):
|
|
239
|
+
print(
|
|
240
|
+
f"supervisor running={supervisor.get('running')} "
|
|
241
|
+
f"pid={supervisor.get('pid')} phase={supervisor.get('phase')}"
|
|
242
|
+
)
|
|
243
|
+
workers = payload.get("workers")
|
|
244
|
+
if not isinstance(workers, list):
|
|
245
|
+
return 0
|
|
246
|
+
print(f"managed_workers={len(workers)}")
|
|
247
|
+
for item in workers:
|
|
248
|
+
if isinstance(item, str):
|
|
249
|
+
print(item)
|
|
250
|
+
continue
|
|
251
|
+
if not isinstance(item, dict):
|
|
252
|
+
continue
|
|
253
|
+
print(
|
|
254
|
+
f"{item.get('name')} app={item.get('app_id')} tool={item.get('tool_name')} "
|
|
255
|
+
f"kind={item.get('worker_kind') or 'infrastructure_worker'} "
|
|
256
|
+
f"phase={item.get('phase')} running={item.get('running')} auto_start={item.get('auto_start')}"
|
|
257
|
+
)
|
|
258
|
+
return 0
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def _detached_supervisor_command(
|
|
262
|
+
resolved_plan,
|
|
263
|
+
*,
|
|
264
|
+
names: tuple[str, ...],
|
|
265
|
+
include_non_autostart: bool,
|
|
266
|
+
poll_interval: float,
|
|
267
|
+
owner_pid: int | None,
|
|
268
|
+
) -> tuple[str, ...]:
|
|
269
|
+
project_dir = str(Path(resolved_plan.project.project_dir).resolve())
|
|
270
|
+
pz_executable = resolve_project_pz_executable(Path(project_dir))
|
|
271
|
+
command: list[str] = [
|
|
272
|
+
pz_executable,
|
|
273
|
+
"pz_foundation",
|
|
274
|
+
"workers",
|
|
275
|
+
"run",
|
|
276
|
+
"--project-dir",
|
|
277
|
+
project_dir,
|
|
278
|
+
"--poll-interval",
|
|
279
|
+
str(float(poll_interval)),
|
|
280
|
+
]
|
|
281
|
+
if include_non_autostart:
|
|
282
|
+
command.append("--all")
|
|
283
|
+
if owner_pid is not None and int(owner_pid) > 0:
|
|
284
|
+
command.extend(["--owner-pid", str(int(owner_pid))])
|
|
285
|
+
command.extend(names)
|
|
286
|
+
return tuple(command)
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def _launch_detached_supervisor(
|
|
290
|
+
resolved_plan,
|
|
291
|
+
*,
|
|
292
|
+
names: tuple[str, ...],
|
|
293
|
+
include_non_autostart: bool,
|
|
294
|
+
poll_interval: float,
|
|
295
|
+
owner_pid: int | None,
|
|
296
|
+
force_restart: bool,
|
|
297
|
+
) -> int:
|
|
298
|
+
auto_start_only = not include_non_autostart and not names
|
|
299
|
+
requested_owner_pid = _coerce_positive_int(owner_pid)
|
|
300
|
+
command = _detached_supervisor_command(
|
|
301
|
+
resolved_plan,
|
|
302
|
+
names=names,
|
|
303
|
+
include_non_autostart=include_non_autostart,
|
|
304
|
+
poll_interval=poll_interval,
|
|
305
|
+
owner_pid=requested_owner_pid,
|
|
306
|
+
)
|
|
307
|
+
logs_dir = Path(resolved_plan.project.runtime_dir) / "managed_workers" / "logs"
|
|
308
|
+
logs_dir.mkdir(parents=True, exist_ok=True)
|
|
309
|
+
log_path = logs_dir / "supervisor.log"
|
|
310
|
+
desired_signature = managed_worker_supervisor_signature(
|
|
311
|
+
resolved_plan,
|
|
312
|
+
names=names,
|
|
313
|
+
auto_start_only=not include_non_autostart and not names,
|
|
314
|
+
)
|
|
315
|
+
worker_targets = list(desired_signature.get("worker_targets") or [])
|
|
316
|
+
existing = managed_worker_status_payload(
|
|
317
|
+
resolved_plan,
|
|
318
|
+
names=names,
|
|
319
|
+
auto_start_only=auto_start_only,
|
|
320
|
+
)
|
|
321
|
+
supervisor = existing.get("supervisor") if isinstance(existing.get("supervisor"), dict) else {}
|
|
322
|
+
workers = tuple(item for item in existing.get("workers", []) if isinstance(item, dict))
|
|
323
|
+
existing_owner_pid = _coerce_positive_int(supervisor.get("owner_pid"))
|
|
324
|
+
owner_stale = False
|
|
325
|
+
if requested_owner_pid is not None:
|
|
326
|
+
owner_stale = existing_owner_pid != requested_owner_pid
|
|
327
|
+
if not owner_stale and existing_owner_pid is not None and not _is_process_alive(existing_owner_pid):
|
|
328
|
+
owner_stale = True
|
|
329
|
+
if not worker_targets:
|
|
330
|
+
if bool(supervisor.get("running")):
|
|
331
|
+
stop_managed_workers(
|
|
332
|
+
resolved_plan,
|
|
333
|
+
timeout_seconds=10.0,
|
|
334
|
+
names=names,
|
|
335
|
+
auto_start_only=auto_start_only,
|
|
336
|
+
)
|
|
337
|
+
return 0
|
|
338
|
+
if force_restart:
|
|
339
|
+
if bool(supervisor.get("running")) or workers:
|
|
340
|
+
stop_managed_workers(
|
|
341
|
+
resolved_plan,
|
|
342
|
+
timeout_seconds=10.0,
|
|
343
|
+
names=names,
|
|
344
|
+
auto_start_only=auto_start_only,
|
|
345
|
+
)
|
|
346
|
+
supervisor = {}
|
|
347
|
+
workers = ()
|
|
348
|
+
signature_matches = (
|
|
349
|
+
str(supervisor.get("pz_env") or "") == str(desired_signature.get("pz_env") or "")
|
|
350
|
+
and list(supervisor.get("worker_targets") or []) == worker_targets
|
|
351
|
+
)
|
|
352
|
+
all_workers_healthy = bool(workers) and all(bool(item.get("healthy")) for item in workers)
|
|
353
|
+
if bool(supervisor.get("running")) and owner_stale:
|
|
354
|
+
stop_managed_workers(
|
|
355
|
+
resolved_plan,
|
|
356
|
+
timeout_seconds=10.0,
|
|
357
|
+
names=names,
|
|
358
|
+
auto_start_only=auto_start_only,
|
|
359
|
+
)
|
|
360
|
+
supervisor = {}
|
|
361
|
+
workers = ()
|
|
362
|
+
signature_matches = False
|
|
363
|
+
all_workers_healthy = False
|
|
364
|
+
if bool(supervisor.get("running")) and signature_matches:
|
|
365
|
+
return 0
|
|
366
|
+
if all_workers_healthy:
|
|
367
|
+
return 0
|
|
368
|
+
if bool(supervisor.get("running")) and not signature_matches:
|
|
369
|
+
stop_managed_workers(
|
|
370
|
+
resolved_plan,
|
|
371
|
+
timeout_seconds=10.0,
|
|
372
|
+
names=names,
|
|
373
|
+
auto_start_only=auto_start_only,
|
|
374
|
+
)
|
|
375
|
+
log_handle = log_path.open("a", encoding="utf-8")
|
|
376
|
+
try:
|
|
377
|
+
subprocess.Popen(
|
|
378
|
+
command,
|
|
379
|
+
cwd=str(resolved_plan.project.project_dir),
|
|
380
|
+
stdout=log_handle,
|
|
381
|
+
stderr=subprocess.STDOUT,
|
|
382
|
+
text=True,
|
|
383
|
+
env=managed_worker_subprocess_env(resolved_plan),
|
|
384
|
+
start_new_session=True,
|
|
385
|
+
close_fds=True,
|
|
386
|
+
)
|
|
387
|
+
finally:
|
|
388
|
+
log_handle.close()
|
|
389
|
+
return 0
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def _restart_detached_supervisor(
|
|
393
|
+
resolved_plan,
|
|
394
|
+
*,
|
|
395
|
+
names: tuple[str, ...],
|
|
396
|
+
include_non_autostart: bool,
|
|
397
|
+
poll_interval: float,
|
|
398
|
+
owner_pid: int | None,
|
|
399
|
+
timeout_seconds: float,
|
|
400
|
+
start_timeout_seconds: float,
|
|
401
|
+
) -> dict[str, object]:
|
|
402
|
+
auto_start_only = not include_non_autostart and not names
|
|
403
|
+
stop_payload = stop_managed_workers(
|
|
404
|
+
resolved_plan,
|
|
405
|
+
timeout_seconds=float(timeout_seconds),
|
|
406
|
+
names=names,
|
|
407
|
+
auto_start_only=auto_start_only,
|
|
408
|
+
)
|
|
409
|
+
launch_code = _launch_detached_supervisor(
|
|
410
|
+
resolved_plan,
|
|
411
|
+
names=names,
|
|
412
|
+
include_non_autostart=include_non_autostart,
|
|
413
|
+
poll_interval=float(poll_interval),
|
|
414
|
+
owner_pid=owner_pid,
|
|
415
|
+
force_restart=False,
|
|
416
|
+
)
|
|
417
|
+
status_payload = _wait_for_restart_status(
|
|
418
|
+
resolved_plan,
|
|
419
|
+
names=names,
|
|
420
|
+
auto_start_only=auto_start_only,
|
|
421
|
+
timeout_seconds=float(start_timeout_seconds),
|
|
422
|
+
)
|
|
423
|
+
return {
|
|
424
|
+
"status": "ok" if launch_code == 0 else "error",
|
|
425
|
+
"code": "PZ_FOUNDATION_MANAGED_WORKERS_RESTARTED",
|
|
426
|
+
"stage": "worker",
|
|
427
|
+
"owner": "pz_foundation",
|
|
428
|
+
"action": "managed_workers_restart",
|
|
429
|
+
"project_dir": str(Path(resolved_plan.project.project_dir).resolve()),
|
|
430
|
+
"launch_requested": launch_code == 0,
|
|
431
|
+
"stop": stop_payload,
|
|
432
|
+
"supervisor": status_payload.get("supervisor"),
|
|
433
|
+
"workers": status_payload.get("workers", []),
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
def _wait_for_restart_status(
|
|
438
|
+
resolved_plan,
|
|
439
|
+
*,
|
|
440
|
+
names: tuple[str, ...],
|
|
441
|
+
auto_start_only: bool,
|
|
442
|
+
timeout_seconds: float = 5.0,
|
|
443
|
+
) -> dict[str, object]:
|
|
444
|
+
deadline = time.time() + max(0.0, float(timeout_seconds))
|
|
445
|
+
payload = managed_worker_status_payload(
|
|
446
|
+
resolved_plan,
|
|
447
|
+
names=names,
|
|
448
|
+
auto_start_only=auto_start_only,
|
|
449
|
+
)
|
|
450
|
+
while time.time() < deadline:
|
|
451
|
+
supervisor = payload.get("supervisor") if isinstance(payload.get("supervisor"), dict) else {}
|
|
452
|
+
workers = payload.get("workers") if isinstance(payload.get("workers"), list) else []
|
|
453
|
+
if bool(supervisor.get("running")) or any(isinstance(item, dict) and item.get("running") for item in workers):
|
|
454
|
+
return payload
|
|
455
|
+
time.sleep(0.1)
|
|
456
|
+
payload = managed_worker_status_payload(
|
|
457
|
+
resolved_plan,
|
|
458
|
+
names=names,
|
|
459
|
+
auto_start_only=auto_start_only,
|
|
460
|
+
)
|
|
461
|
+
return payload
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
def main(argv: list[str] | None = None, *, project_dir: str | None = None, plan=None) -> int:
|
|
465
|
+
parser = _build_parser()
|
|
466
|
+
ns = parser.parse_args(list(argv or []))
|
|
467
|
+
command = ns.command or "list"
|
|
468
|
+
json_output = bool(getattr(ns, "json_output", False))
|
|
469
|
+
resolved_plan = plan or compile_runtime_plan(project_dir=project_dir or ns.project_dir)
|
|
470
|
+
include_non_autostart = bool(getattr(ns, "include_non_autostart", False))
|
|
471
|
+
names = tuple(str(item).strip() for item in getattr(ns, "names", ()) if str(item).strip())
|
|
472
|
+
auto_start_only = not include_non_autostart and not names
|
|
473
|
+
force_restart = (
|
|
474
|
+
bool(ns.force_restart)
|
|
475
|
+
if hasattr(ns, "force_restart")
|
|
476
|
+
else _force_restart_on_host_start(resolved_plan)
|
|
477
|
+
)
|
|
478
|
+
try:
|
|
479
|
+
if command in {"list", "status"}:
|
|
480
|
+
payload = managed_worker_status_payload(
|
|
481
|
+
resolved_plan,
|
|
482
|
+
names=names,
|
|
483
|
+
auto_start_only=auto_start_only,
|
|
484
|
+
)
|
|
485
|
+
return _emit(payload, json_output=json_output)
|
|
486
|
+
if command == "run":
|
|
487
|
+
owner_pid = getattr(ns, "owner_pid", None)
|
|
488
|
+
if bool(getattr(ns, "detach", False)):
|
|
489
|
+
return _launch_detached_supervisor(
|
|
490
|
+
resolved_plan,
|
|
491
|
+
names=names,
|
|
492
|
+
include_non_autostart=include_non_autostart,
|
|
493
|
+
poll_interval=float(ns.poll_interval),
|
|
494
|
+
owner_pid=owner_pid,
|
|
495
|
+
force_restart=force_restart,
|
|
496
|
+
)
|
|
497
|
+
supervisor = ManagedWorkerSupervisor(
|
|
498
|
+
resolved_plan,
|
|
499
|
+
names=names,
|
|
500
|
+
auto_start_only=auto_start_only,
|
|
501
|
+
poll_interval_seconds=float(ns.poll_interval),
|
|
502
|
+
owner_pid=owner_pid,
|
|
503
|
+
)
|
|
504
|
+
return supervisor.run()
|
|
505
|
+
if command == "stop":
|
|
506
|
+
payload = stop_managed_workers(
|
|
507
|
+
resolved_plan,
|
|
508
|
+
timeout_seconds=float(ns.timeout),
|
|
509
|
+
names=names,
|
|
510
|
+
auto_start_only=auto_start_only,
|
|
511
|
+
)
|
|
512
|
+
return _emit(payload, json_output=json_output)
|
|
513
|
+
if command == "restart":
|
|
514
|
+
payload = _restart_detached_supervisor(
|
|
515
|
+
resolved_plan,
|
|
516
|
+
names=names,
|
|
517
|
+
include_non_autostart=include_non_autostart,
|
|
518
|
+
poll_interval=float(ns.poll_interval),
|
|
519
|
+
owner_pid=getattr(ns, "owner_pid", None),
|
|
520
|
+
timeout_seconds=float(ns.timeout),
|
|
521
|
+
start_timeout_seconds=float(ns.start_timeout),
|
|
522
|
+
)
|
|
523
|
+
return _emit(payload, json_output=json_output)
|
|
524
|
+
parser.print_help()
|
|
525
|
+
return 0
|
|
526
|
+
except Exception as exc:
|
|
527
|
+
error = as_pz_error(
|
|
528
|
+
exc,
|
|
529
|
+
code="PZ_FOUNDATION_MANAGED_WORKERS_FAILED",
|
|
530
|
+
stage="worker",
|
|
531
|
+
owner="pz_foundation",
|
|
532
|
+
action="managed_workers",
|
|
533
|
+
)
|
|
534
|
+
if json_output:
|
|
535
|
+
payload = error.to_dict()
|
|
536
|
+
payload["status"] = "error"
|
|
537
|
+
print(json.dumps(payload, ensure_ascii=True, sort_keys=True))
|
|
538
|
+
else:
|
|
539
|
+
sys.stderr.write(f"{error}\n")
|
|
540
|
+
return 1
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
if __name__ == "__main__":
|
|
544
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
class ManagedWorkersCliTool:
|
|
548
|
+
def configure(self, parser) -> None: # noqa: ANN001
|
|
549
|
+
return None
|
|
550
|
+
|
|
551
|
+
def run(self, ctx) -> int: # noqa: ANN001
|
|
552
|
+
return main(
|
|
553
|
+
list(getattr(ctx, "argv", ()) or ()),
|
|
554
|
+
project_dir=str(ctx.project.project_dir),
|
|
555
|
+
plan=ctx.plan,
|
|
556
|
+
)
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
tool = CliToolSpec(
|
|
560
|
+
id="pz_foundation.workers",
|
|
561
|
+
owner_app="pz_foundation",
|
|
562
|
+
command=("workers",),
|
|
563
|
+
summary="Manage project-attached worker runtimes.",
|
|
564
|
+
tool=ManagedWorkersCliTool(),
|
|
565
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Secret placeholders for pz_foundation.
|
|
2
|
+
pz_foundation__database__password=
|
|
3
|
+
pz_foundation__database__ssl_password=
|
|
4
|
+
pz_foundation__cache__password=
|
|
5
|
+
pz_foundation__mail__password=
|
|
6
|
+
pz_foundation__observability__logger__feishu__webhook=
|
|
7
|
+
pz_foundation__observability__logger__feishu__secret=
|
|
8
|
+
pz_foundation__observability__logger__feishu__webhook_error_event=
|
|
9
|
+
pz_foundation__observability__logger__feishu__secret_error_event=
|
|
10
|
+
pz_foundation__observability__logger__feishu__webhook_warning_event=
|
|
11
|
+
pz_foundation__observability__logger__feishu__secret_warning_event=
|
|
12
|
+
pz_foundation__observability__logger__feishu__webhook_custom_event=
|
|
13
|
+
pz_foundation__observability__logger__feishu__secret_custom_event=
|
|
14
|
+
pz_foundation__storage__access_key_id=
|
|
15
|
+
pz_foundation__storage__secret_access_key=
|