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
4 changes: 3 additions & 1 deletion docs/specifications/post-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ Container startup failed: 2 of 3 instances did not become ready.

### 起動の後の処理の段

`_run_post_start(project_name, scale, indices, dev_service_name, config, compose_file, run_deploy=True)` は、
`_run_post_start(deployment, indices, config, run_deploy=True)` は、
後処理の対象 `indices` へ次の順で処理を行う。対象が空なら何も行わない(token も発行しない)。
`deployment` は起動した構成(`_ComposeDeployment`。`project_name`・`scale`・`dev_service_name`・`compose_file` の組)で、
`up` / `scale` / `project post-start` が組んで渡す。

| 順 | 処理 | 条件 | 失敗したとき |
| --- | --- | --- | --- |
Expand Down
36 changes: 28 additions & 8 deletions lib/devbase/commands/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import time
from contextlib import contextmanager
from dataclasses import dataclass
from datetime import datetime, timezone
from pathlib import Path
from typing import List, Optional
Expand Down Expand Up @@ -1273,8 +1274,21 @@ def _run_pre_up_checks(config) -> bool:
return True


def _run_post_start(project_name: str, scale: int, indices, dev_service_name: str,
config, compose_file, run_deploy: bool = True) -> None:
@dataclass(frozen=True)
class _ComposeDeployment:
"""起動した構成。``up`` / ``scale`` / ``project post-start`` が起動の後の処理の段へ渡す組。

``compose_file`` は ``-f`` で渡すファイル (スケールのファイルが無ければ ``None``)。
"""

project_name: str
scale: int
dev_service_name: str
compose_file: Optional[Path]


def _run_post_start(deployment: _ComposeDeployment, indices, config,
run_deploy: bool = True) -> None:
"""起動の後の処理の段。後処理の対象の番号へ、インスタンスごとの処理を決まった順に行う。

順は、不足リポジトリの報告 → ``./deploy`` → token の配布 → 窓のタイトルの設定で、
Expand All @@ -1287,6 +1301,10 @@ def _run_post_start(project_name: str, scale: int, indices, dev_service_name: st
indices = list(indices)
if not indices:
return
project_name = deployment.project_name
scale = deployment.scale
dev_service_name = deployment.dev_service_name
compose_file = deployment.compose_file

# clone できなかった repo があれば伝える (揃っていれば何も出さない)。
_report_missing_repos(config, scale, dev_service_name, project_name,
Expand Down Expand Up @@ -1450,8 +1468,9 @@ def cmd_up(project_name: str = None, scale: int = None,
if startup_error is not None:
_warn_partial_start(startup_error, started, dev_service_name)

_run_post_start(project_name, scale, started, dev_service_name, config,
override_file)
_run_post_start(
_ComposeDeployment(project_name, scale, dev_service_name, override_file),
started, config)

_maybe_open_editor(project_name, open_editor, open_index, scale,
config, compose_file=override_file,
Expand Down Expand Up @@ -1565,8 +1584,8 @@ def cmd_post_start(project_name: Optional[str] = None, context: Optional[str] =
return 1

compose_file = _SCALE_COMPOSE_FILE if _SCALE_COMPOSE_FILE.exists() else None
_run_post_start(project_name, scale, targets, dev_service_name, config, compose_file,
run_deploy=False)
_run_post_start(_ComposeDeployment(project_name, scale, dev_service_name, compose_file),
targets, config, run_deploy=False)
logger.info("=== Post-start completed ===")
return 0

Expand Down Expand Up @@ -1882,8 +1901,9 @@ def cmd_scale(new_scale: int, project_name: str = None,
if startup_error is not None:
_warn_partial_start(startup_error, targets, dev_service_name)

_run_post_start(project_name, new_scale, targets, dev_service_name, config,
override_file)
_run_post_start(
_ComposeDeployment(project_name, new_scale, dev_service_name, override_file),
targets, config)

if _finish_partial('Scale', startup_error, project_name):
return 1
Expand Down
Loading
Loading