Skip to content

Commit 756ad10

Browse files
authored
ログメッセージにproject_idを加えて、分かりやすくする (#373)
* update swagger * update * update * update * update * updat teravis * update * poetry update
1 parent bfaa505 commit 756ad10

File tree

14 files changed

+430
-316
lines changed

14 files changed

+430
-316
lines changed

.vscode/cspell.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
"favicon",
2323
"giveup",
2424
"kurusugawa",
25+
"netrc",
2526
"pydata",
2627
"pylint",
2728
"tzlocal"
2829
]
29-
}
30+
}

annofabapi/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.50.0"
1+
__version__ = "0.50.1"

annofabapi/dataclass/job.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from dataclasses_json import DataClassJsonMixin
1717

18-
from annofabapi.models import JobStatus, ProjectJobType
18+
from annofabapi.models import Errors, JobStatus, ProjectJobType
1919

2020

2121
@dataclass
@@ -40,6 +40,9 @@ class ProjectJobInfo(DataClassJsonMixin):
4040
job_detail: Optional[Dict[str, Any]]
4141
"""ジョブ結果の内部情報"""
4242

43+
errors: Optional[Errors]
44+
""""""
45+
4346
created_datetime: Optional[str]
4447
""""""
4548

annofabapi/generated_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ def get_organization_job(
11061106
type (str): 取得するジョブの種別。[詳細はこちら](#section/OrganizationJobType)。
11071107
page (int): 検索結果のうち、取得したいページの番号(1始まり) 現在は未実装のパラメータです。(今後対応予定)
11081108
limit (int): 1ページあたりの取得するデータ件数。 未指定時は1件のみ取得。
1109-
exclusive_start_created_datetime (str): 取得するデータの直前の作成日時
1109+
exclusive_start_created_datetime (str): 取得するデータの直前の作成日時(ISO 8601 拡張形式)
11101110
11111111
Returns:
11121112
Tuple[OrganizationJobInfoContainer, requests.Response]
@@ -1138,7 +1138,7 @@ def get_project_job(
11381138
type (ProjectJobType): 取得するジョブの種別。[詳細はこちら](#section/ProjectJobType)。
11391139
page (int): 検索結果のうち、取得したいページの番号(1始まり) 現在は未実装のパラメータです。(今後対応予定)
11401140
limit (int): 1ページあたりの取得するデータ件数。 未指定時は1件のみ取得。
1141-
exclusive_start_created_datetime (str): 取得するデータの直前の作成日時
1141+
exclusive_start_created_datetime (str): 取得するデータの直前の作成日時(ISO 8601 拡張形式)
11421142
11431143
Returns:
11441144
Tuple[ProjectJobInfoContainer, requests.Response]

annofabapi/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,6 +2531,8 @@ class JobStatus(Enum):
25312531
ジョブの内部情報
25322532
* job_detail: __DictStrKeyAnyValue__
25332533
ジョブ結果の内部情報
2534+
* errors: Errors
2535+
25342536
* created_datetime: str
25352537
25362538
* updated_datetime: str
@@ -2718,6 +2720,8 @@ class JobStatus(Enum):
27182720
ジョブの内部情報
27192721
* job_detail: __DictStrKeyAnyValue__
27202722
ジョブ結果の内部情報
2723+
* errors: Errors
2724+
27212725
* created_datetime: str
27222726
27232727
* updated_datetime: str
@@ -3308,6 +3312,8 @@ class PricePlan(Enum):
33083312
ジョブの内部情報
33093313
* job_detail: __DictStrKeyAnyValue__
33103314
ジョブ結果の内部情報
3315+
* errors: Errors
3316+
33113317
* created_datetime: str
33123318
33133319
* updated_datetime: str

annofabapi/resource.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ def __init__(self, login_user_id: str, login_password: str, endpoint_url: str =
3232
#: AnnofabApi2 Instance
3333
self.api2 = AnnofabApi2(self.api)
3434

35+
logger.debug(
36+
"Create annofabapi resource instance :: %s", {"login_user_id": login_user_id, "endpoint_url": endpoint_url}
37+
)
38+
3539

3640
def build(
3741
login_user_id: Optional[str] = None, login_password: Optional[str] = None, endpoint_url: str = DEFAULT_ENDPOINT_URL
@@ -75,13 +79,13 @@ def build(
7579

7680
def build_from_netrc(endpoint_url: str = DEFAULT_ENDPOINT_URL) -> Resource:
7781
"""
78-
``.netrc`` ファイルから、annnofabapi.Resourceインスタンスを生成する。
82+
``.netrc`` ファイルから、annofabapi.Resourceインスタンスを生成する。
7983
8084
Args:
8185
endpoint_url: AnnoFab APIのエンドポイント。
8286
8387
Returns:
84-
annnofabapi.Resourceインスタンス
88+
annofabapi.Resourceインスタンス
8589
8690
"""
8791
try:
@@ -100,25 +104,23 @@ def build_from_netrc(endpoint_url: str = DEFAULT_ENDPOINT_URL) -> Resource:
100104
if login_user_id is None or login_password is None:
101105
raise AnnofabApiException("User ID or password in the .netrc file are None.")
102106

103-
logger.debug(".netrcファイルからAnnoFab認証情報を読み込みました。")
104107
return Resource(login_user_id, login_password, endpoint_url=endpoint_url)
105108

106109

107110
def build_from_env(endpoint_url: str = DEFAULT_ENDPOINT_URL) -> Resource:
108111
"""
109-
環境変数 ``ANNOFAB_USER_ID`` , ``ANNOFAB_PASSWORD`` から、annnofabapi.Resourceインスタンスを生成する。
112+
環境変数 ``ANNOFAB_USER_ID`` , ``ANNOFAB_PASSWORD`` から、annofabapi.Resourceインスタンスを生成する。
110113
111114
Args:
112115
endpoint_url: AnnoFab APIのエンドポイント。
113116
114117
Returns:
115-
annnofabapi.Resourceインスタンス
118+
annofabapi.Resourceインスタンス
116119
117120
"""
118121
login_user_id = os.environ.get("ANNOFAB_USER_ID")
119122
login_password = os.environ.get("ANNOFAB_PASSWORD")
120123
if login_user_id is None or login_password is None:
121124
raise AnnofabApiException("`ANNOFAB_USER_ID` or `ANNOFAB_PASSWORD` environment variable are empty.")
122125

123-
logger.debug("環境変数からAnnoFab認証情報を読み込みました。")
124126
return Resource(login_user_id, login_password, endpoint_url=endpoint_url)

annofabapi/wrapper.py

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ def download_annotation_archive(self, project_id: str, dest_path: str) -> str:
246246
_, response = self.api.get_annotation_archive(project_id, query_params=query_params)
247247
url = response.headers["Location"]
248248
response2 = _download(url, dest_path)
249-
logger.debug(f"type=simple_annotation, Last-Modified={response2.headers.get('Last-Modified')}")
249+
logger.debug(
250+
f"project_id='{project_id}', type=simple_annotation, Last-Modified={response2.headers.get('Last-Modified')}"
251+
)
250252
return url
251253

252254
def download_full_annotation_archive(self, project_id: str, dest_path: str) -> str:
@@ -267,7 +269,9 @@ def download_full_annotation_archive(self, project_id: str, dest_path: str) -> s
267269
_, response = self.api.get_archive_full_with_pro_id(project_id)
268270
url = response.headers["Location"]
269271
response2 = _download(url, dest_path)
270-
logger.debug(f"type=full_annotation, Last-Modified={response2.headers.get('Last-Modified')}")
272+
logger.debug(
273+
f"project_id='{project_id}', type=full_annotation, Last-Modified={response2.headers.get('Last-Modified')}"
274+
)
271275
return url
272276

273277
def get_all_annotation_list(
@@ -357,7 +361,7 @@ def __to_dest_annotation_detail(
357361
s3_path = self.upload_data_to_s3(
358362
dest_project_id, data=src_response.content, content_type=src_response.headers["Content-Type"]
359363
)
360-
logger.debug("%s に外部アノテーションファイルをアップロードしました。", s3_path)
364+
logger.debug("project_id='%s', %s に外部アノテーションファイルをアップロードしました。", dest_project_id, s3_path)
361365
dest_detail["path"] = s3_path
362366
dest_detail["url"] = None
363367
dest_detail["etag"] = None
@@ -427,7 +431,7 @@ def copy_annotation(
427431
src_annotation_details: List[Dict[str, Any]] = src_annotation["details"]
428432

429433
if len(src_annotation_details) == 0:
430-
logger.debug("コピー元にアノテーションが1つもないため、アノテーションのコピーをスキップします。")
434+
logger.debug(f"コピー元にアノテーションが1つもないため、アノテーションのコピーをスキップします。:: src='{src}'")
431435
return False
432436

433437
old_dest_annotation, _ = self.api.get_editor_annotation(dest.project_id, dest.task_id, dest.input_data_id)
@@ -574,7 +578,7 @@ def __to_annotation_detail_for_request(
574578
try:
575579
s3_path = self.upload_data_to_s3(project_id, f, content_type="image/png")
576580
dest_obj["path"] = s3_path
577-
logger.debug(f"{outer_file_path} をS3にアップロードしました。")
581+
logger.debug(f"project_id='{project_id}', {outer_file_path} をS3にアップロードしました。")
578582

579583
except CheckSumError as e:
580584
message = (
@@ -1574,7 +1578,9 @@ def download_project_inputs_url(self, project_id: str, dest_path: str) -> str:
15741578
content, _ = self.api.get_project_inputs_url(project_id)
15751579
url = content["url"]
15761580
response2 = _download(url, dest_path)
1577-
logger.debug(f"type=input_data, Last-Modified={response2.headers.get('Last-Modified')}")
1581+
logger.debug(
1582+
f"project_id='{project_id}', type=input_data, Last-Modified={response2.headers.get('Last-Modified')}"
1583+
)
15781584
return url
15791585

15801586
def download_project_tasks_url(self, project_id: str, dest_path: str) -> str:
@@ -1594,7 +1600,7 @@ def download_project_tasks_url(self, project_id: str, dest_path: str) -> str:
15941600
content, _ = self.api.get_project_tasks_url(project_id)
15951601
url = content["url"]
15961602
response2 = _download(url, dest_path)
1597-
logger.debug(f"type=task, Last-Modified={response2.headers.get('Last-Modified')}")
1603+
logger.debug(f"project_id='{project_id}', type=task, Last-Modified={response2.headers.get('Last-Modified')}")
15981604
return url
15991605

16001606
def download_project_inspections_url(self, project_id: str, dest_path: str) -> str:
@@ -1614,7 +1620,10 @@ def download_project_inspections_url(self, project_id: str, dest_path: str) -> s
16141620
content, _ = self.api.get_project_inspections_url(project_id)
16151621
url = content["url"]
16161622
response2 = _download(url, dest_path)
1617-
logger.debug(f"type=inspection_comment, Last-Modified={response2.headers.get('Last-Modified')}")
1623+
logger.debug(
1624+
f"project_id='{project_id}', type=inspection_comment,"
1625+
f"Last-Modified={response2.headers.get('Last-Modified')}"
1626+
)
16181627
return url
16191628

16201629
def download_project_task_history_events_url(self, project_id: str, dest_path: str) -> str:
@@ -1634,7 +1643,10 @@ def download_project_task_history_events_url(self, project_id: str, dest_path: s
16341643
content, _ = self.api.get_project_task_history_events_url(project_id)
16351644
url = content["url"]
16361645
response2 = _download(url, dest_path)
1637-
logger.debug(f"type=task_history_event, Last-Modified={response2.headers.get('Last-Modified')}")
1646+
logger.debug(
1647+
f"project_id='{project_id}', type=task_history_event, "
1648+
f"Last-Modified={response2.headers.get('Last-Modified')}"
1649+
)
16381650
return url
16391651

16401652
def download_project_task_histories_url(self, project_id: str, dest_path: str) -> str:
@@ -1654,7 +1666,9 @@ def download_project_task_histories_url(self, project_id: str, dest_path: str) -
16541666
content, _ = self.api.get_project_task_histories_url(project_id)
16551667
url = content["url"]
16561668
response2 = _download(url, dest_path)
1657-
logger.debug(f"type=task_history, Last-Modified={response2.headers.get('Last-Modified')}")
1669+
logger.debug(
1670+
f"project_id='{project_id}', type=task_history, Last-Modified={response2.headers.get('Last-Modified')}"
1671+
)
16581672
return url
16591673

16601674
#########################################
@@ -2068,7 +2082,7 @@ def delete_all_succeeded_job(self, project_id: str, job_type: ProjectJobType) ->
20682082
deleted_jobs = []
20692083
for job in jobs:
20702084
if job["job_status"] == "succeeded":
2071-
logger.debug("job_id=%s のジョブを削除します。", job["job_id"])
2085+
logger.debug(f"project_id='{project_id}', job_id='{job['job_id']}'のジョブを削除します。")
20722086
self.api.delete_project_job(project_id, job_type=job_type.value, job_id=job["job_id"])
20732087
deleted_jobs.append(job)
20742088

@@ -2188,37 +2202,45 @@ def get_job_from_job_id(arg_job_id: str) -> Optional[ProjectJobInfo]:
21882202
# 初回のみ
21892203
job = get_latest_job()
21902204
if job is None or job["job_status"] != JobStatus.PROGRESS.value:
2191-
logger.debug("job_type='%s' である進行中のジョブは存在しません。", job_type.value)
2205+
logger.debug("project_id='%s', job_type='%s' である進行中のジョブは存在しません。", project_id, job_type.value)
21922206
return None
21932207
job_id = job["job_id"]
21942208

21952209
if job is None:
2196-
logger.debug("job_id='%s', job_type='%s' のジョブは存在しません。", job_type.value, job_id)
2210+
logger.debug(
2211+
"project_id='%s', job_id='%s', job_type='%s' のジョブは存在しません。", project_id, job_type.value, job_id
2212+
)
21972213
return None
21982214

21992215
job_access_count += 1
22002216

22012217
if job["job_status"] == JobStatus.SUCCEEDED.value:
2202-
logger.debug("job_id='%s', job_type='%s' のジョブが成功しました。", job_id, job_type.value)
2218+
logger.debug(
2219+
"project_id='%s', job_id='%s', job_type='%s' のジョブが成功しました。", project_id, job_id, job_type.value
2220+
)
22032221
return JobStatus.SUCCEEDED
22042222

22052223
elif job["job_status"] == JobStatus.FAILED.value:
2206-
logger.debug("job_id='%s', job_type='%s' のジョブが失敗しました。", job_id, job_type.value)
2224+
logger.debug(
2225+
"project_id='%s', job_id='%s', job_type='%s' のジョブが失敗しました。", project_id, job_id, job_type.value
2226+
)
22072227
return JobStatus.FAILED
22082228

22092229
else:
22102230
# 進行中
22112231
if job_access_count < max_job_access:
22122232
logger.debug(
2213-
"job_id='%s', job_type='%s' のジョブは進行中です。%d 秒間待ちます。",
2233+
"project_id='%s', job_id='%s', job_type='%s' のジョブは進行中です。%d 秒間待ちます。",
2234+
project_id,
22142235
job_id,
22152236
job_type.value,
22162237
job_access_interval,
22172238
)
22182239
time.sleep(job_access_interval)
22192240
else:
22202241
logger.debug(
2221-
"job_id='%s', job_type='%s' のジョブは %.1f 分以上経過しても、終了しませんでした。",
2242+
"project_id='%s', job_id='%s', job_type='%s' のジョブは %.1f 分以上経過しても、終了しませんでした。",
2243+
project_id,
22222244
job["job_id"],
22232245
job_type.value,
22242246
job_access_interval * job_access_count / 60,
@@ -2407,7 +2429,7 @@ def _to_new_data(labor: Dict[str, Any]) -> Dict[str, Any]:
24072429
dt_new_to_date = dt_from_date + datetime.timedelta(days=diff_days // 2)
24082430
dt_new_from_date = dt_new_to_date + datetime.timedelta(days=1)
24092431
logger.debug(
2410-
"取得対象の期間が広すぎるため、データを取得できませんでした。"
2432+
f"project_id='{project_id}': 取得対象の期間が広すぎるため、データを取得できませんでした。"
24112433
f"取得対象の期間を{from_date}~{dt_new_to_date.strftime(DATE_FORMAT)}, "
24122434
f"{dt_new_from_date.strftime(DATE_FORMAT)}~{to_date}に分割して、再度取得します。"
24132435
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from annofabapi._utils import deprecated_class
2-
from annofabapi.models import JobStatus, ProjectJobType
2+
from annofabapi.models import JobStatus, ProjectJobType, Errors

generate/swagger/swagger-api-components.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,8 @@ components:
13001300
job_detail:
13011301
type: object
13021302
description: ジョブ結果の内部情報
1303+
errors:
1304+
$ref: "#/components/schemas/Errors"
13031305
created_datetime:
13041306
type: string
13051307
format: date-time
@@ -1323,6 +1325,8 @@ components:
13231325
job_detail:
13241326
type: object
13251327
description: ジョブ結果の内部情報
1328+
errors:
1329+
$ref: "#/components/schemas/Errors"
13261330
created_datetime:
13271331
type: string
13281332
format: date-time

generate/swagger/swagger.v2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ info:
115115
116116
上記例 `account_id_count` は、タスクのフィールド `account_id` でタスクを分類したところ「`account_id` が `c5eee002` であるタスクが9件、`9f110e48` であるタスクが5件、`b25dfeb3` であるタスクが1件」だったという結果を表しています。
117117
118-
version: 0.125.0
118+
version: 0.127.0
119119
title: AnnoFab Web API
120120
x-logo:
121121
url: "https://annofab.com/resource/images/logo_landscape.png"

0 commit comments

Comments
 (0)