Convert every description of a plan read in one adf-codec container run, and take a heavy slot around the build of the codec's image
CI / tests (pull_request) Successful in 2m57s
CI / tests (pull_request) Successful in 2m57s
This commit is contained in:
+13
-20
@@ -4,13 +4,12 @@ An item is an open child issue. Its ID is the issue's number, so every child mus
|
||||
|
||||
The store only reads so far: every write is a Failure."""
|
||||
import base64
|
||||
import concurrent.futures
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import re
|
||||
import typing
|
||||
|
||||
from adf_codec.convert import adf_to_markdown
|
||||
from adf_codec.convert import adfs_to_markdown, Refused
|
||||
from plan_store.markdown_edits import bold_cell
|
||||
from project_config.settings import Epic
|
||||
from release_plan.todo_table import EXEMPTIONS, is_exempt, Item, MOVES, parse_moves, parse_scores, SHAPE
|
||||
@@ -30,13 +29,11 @@ TIMEOUT = 30
|
||||
PAGE = 100
|
||||
# The pages one read asks for at most, so an answer that never names a last page ends the read.
|
||||
MAX_PAGES = 100
|
||||
# The adf-codec containers run at once, each converting one description: one heavy slot's CPUs.
|
||||
CONVERSIONS = 4
|
||||
READ_ONLY = "a plan in Jira is only read so far: file, edit and finish its issues in Jira"
|
||||
|
||||
# Sends a request with the Authorization header given, the body as JSON where there is one, and returns the JSON answer, or a Failure saying why there is none.
|
||||
Http = typing.Callable[[str, str, str, object], object]
|
||||
ToMarkdown = typing.Callable[[dict[str, typing.Any]], str | Failure]
|
||||
ToMarkdown = typing.Callable[[list[dict[str, typing.Any]]], list[str] | Refused | Failure]
|
||||
|
||||
|
||||
def http_json(method: str, url: str, authorization: str, body: object) -> object:
|
||||
@@ -75,7 +72,7 @@ class JiraPlan:
|
||||
epic: Epic
|
||||
env_file: pathlib.Path
|
||||
http: Http = http_json
|
||||
to_markdown: ToMarkdown = adf_to_markdown
|
||||
to_markdown: ToMarkdown = adfs_to_markdown
|
||||
|
||||
@property
|
||||
def label(self) -> str:
|
||||
@@ -164,8 +161,8 @@ def plan_of(issues: list[Issue], epic: Epic, to_markdown: ToMarkdown) -> Plan |
|
||||
items = [item(issue, project, ids) for issue in issues]
|
||||
if failed := next((found for found in items if isinstance(found, Failure)), None):
|
||||
return failed
|
||||
# The descriptions convert last, since each costs a container run, which a read that fails doesn't need.
|
||||
texts = details(issues, to_markdown)
|
||||
# The descriptions convert last, since that costs a container run, which a read that fails doesn't need.
|
||||
texts = details(issues, epic, to_markdown)
|
||||
if isinstance(texts, Failure):
|
||||
return texts
|
||||
return Plan([dataclasses.replace(found, detail=texts.get(found.id, "")) for found in items if isinstance(found, Item)])
|
||||
@@ -175,19 +172,15 @@ def number(key: str) -> int:
|
||||
return int(key.rpartition("-")[2])
|
||||
|
||||
|
||||
def details(issues: list[Issue], to_markdown: ToMarkdown) -> dict[int, str] | Failure:
|
||||
"""Each described issue's description as markdown, under the issue's number. The first converts alone, since that run builds the codec's image where the machine has none; the rest convert CONVERSIONS at a time."""
|
||||
def details(issues: list[Issue], epic: Epic, to_markdown: ToMarkdown) -> dict[int, str] | Failure:
|
||||
"""Each described issue's description as markdown, under the issue's number, all converted at once."""
|
||||
described = [(issue, issue.description) for issue in issues if issue.description is not None]
|
||||
texts: list[str | Failure] = [to_markdown(description) for _, description in described[:1]]
|
||||
if not any(isinstance(text, Failure) for text in texts):
|
||||
with concurrent.futures.ThreadPoolExecutor(CONVERSIONS) as pool:
|
||||
texts += pool.map(to_markdown, [description for _, description in described[1:]])
|
||||
found = {}
|
||||
for (issue, _), text in zip(described, texts):
|
||||
if isinstance(text, Failure):
|
||||
return Failure(f"{issue.key}'s description: {text.reason}")
|
||||
found[issue.number] = text.strip()
|
||||
return found
|
||||
texts = to_markdown([description for _, description in described])
|
||||
if isinstance(texts, Refused):
|
||||
return Failure(f"{described[texts.index][0].key}'s description: {texts.failure.reason}")
|
||||
if isinstance(texts, Failure):
|
||||
return Failure(f"cannot convert the descriptions of {epic.key}'s children to markdown: {texts.reason}")
|
||||
return {issue.number: text.strip() for (issue, _), text in zip(described, texts)}
|
||||
|
||||
|
||||
def item(issue: Issue, project: str, ids: set[int]) -> Item | Failure:
|
||||
|
||||
Reference in New Issue
Block a user