Skip to content

Commit

Permalink
ログメッセージにproject_idを加えて、分かりやすくする (#373)
Browse files Browse the repository at this point in the history
* update swagger

* update

* update

* update

* update

* updat teravis

* update

* poetry update
  • Loading branch information
yuji38kwmt committed Nov 18, 2021
1 parent bfaa505 commit 756ad10
Show file tree
Hide file tree
Showing 14 changed files with 430 additions and 316 deletions.
3 changes: 2 additions & 1 deletion .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
"favicon",
"giveup",
"kurusugawa",
"netrc",
"pydata",
"pylint",
"tzlocal"
]
}
}
2 changes: 1 addition & 1 deletion annofabapi/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.50.0"
__version__ = "0.50.1"
5 changes: 4 additions & 1 deletion annofabapi/dataclass/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from dataclasses_json import DataClassJsonMixin

from annofabapi.models import JobStatus, ProjectJobType
from annofabapi.models import Errors, JobStatus, ProjectJobType


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

errors: Optional[Errors]
""""""

created_datetime: Optional[str]
""""""

Expand Down
4 changes: 2 additions & 2 deletions annofabapi/generated_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ def get_organization_job(
type (str): 取得するジョブの種別。[詳細はこちら](#section/OrganizationJobType)。
page (int): 検索結果のうち、取得したいページの番号(1始まり) 現在は未実装のパラメータです。(今後対応予定)
limit (int): 1ページあたりの取得するデータ件数。 未指定時は1件のみ取得。
exclusive_start_created_datetime (str): 取得するデータの直前の作成日時
exclusive_start_created_datetime (str): 取得するデータの直前の作成日時(ISO 8601 拡張形式)
Returns:
Tuple[OrganizationJobInfoContainer, requests.Response]
Expand Down Expand Up @@ -1138,7 +1138,7 @@ def get_project_job(
type (ProjectJobType): 取得するジョブの種別。[詳細はこちら](#section/ProjectJobType)。
page (int): 検索結果のうち、取得したいページの番号(1始まり) 現在は未実装のパラメータです。(今後対応予定)
limit (int): 1ページあたりの取得するデータ件数。 未指定時は1件のみ取得。
exclusive_start_created_datetime (str): 取得するデータの直前の作成日時
exclusive_start_created_datetime (str): 取得するデータの直前の作成日時(ISO 8601 拡張形式)
Returns:
Tuple[ProjectJobInfoContainer, requests.Response]
Expand Down
6 changes: 6 additions & 0 deletions annofabapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2531,6 +2531,8 @@ class JobStatus(Enum):
ジョブの内部情報
* job_detail: __DictStrKeyAnyValue__
ジョブ結果の内部情報
* errors: Errors
* created_datetime: str
* updated_datetime: str
Expand Down Expand Up @@ -2718,6 +2720,8 @@ class JobStatus(Enum):
ジョブの内部情報
* job_detail: __DictStrKeyAnyValue__
ジョブ結果の内部情報
* errors: Errors
* created_datetime: str
* updated_datetime: str
Expand Down Expand Up @@ -3308,6 +3312,8 @@ class PricePlan(Enum):
ジョブの内部情報
* job_detail: __DictStrKeyAnyValue__
ジョブ結果の内部情報
* errors: Errors
* created_datetime: str
* updated_datetime: str
Expand Down
14 changes: 8 additions & 6 deletions annofabapi/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def __init__(self, login_user_id: str, login_password: str, endpoint_url: str =
#: AnnofabApi2 Instance
self.api2 = AnnofabApi2(self.api)

logger.debug(
"Create annofabapi resource instance :: %s", {"login_user_id": login_user_id, "endpoint_url": endpoint_url}
)


def build(
login_user_id: Optional[str] = None, login_password: Optional[str] = None, endpoint_url: str = DEFAULT_ENDPOINT_URL
Expand Down Expand Up @@ -75,13 +79,13 @@ def build(

def build_from_netrc(endpoint_url: str = DEFAULT_ENDPOINT_URL) -> Resource:
"""
``.netrc`` ファイルから、annnofabapi.Resourceインスタンスを生成する。
``.netrc`` ファイルから、annofabapi.Resourceインスタンスを生成する。
Args:
endpoint_url: AnnoFab APIのエンドポイント。
Returns:
annnofabapi.Resourceインスタンス
annofabapi.Resourceインスタンス
"""
try:
Expand All @@ -100,25 +104,23 @@ def build_from_netrc(endpoint_url: str = DEFAULT_ENDPOINT_URL) -> Resource:
if login_user_id is None or login_password is None:
raise AnnofabApiException("User ID or password in the .netrc file are None.")

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


def build_from_env(endpoint_url: str = DEFAULT_ENDPOINT_URL) -> Resource:
"""
環境変数 ``ANNOFAB_USER_ID`` , ``ANNOFAB_PASSWORD`` から、annnofabapi.Resourceインスタンスを生成する。
環境変数 ``ANNOFAB_USER_ID`` , ``ANNOFAB_PASSWORD`` から、annofabapi.Resourceインスタンスを生成する。
Args:
endpoint_url: AnnoFab APIのエンドポイント。
Returns:
annnofabapi.Resourceインスタンス
annofabapi.Resourceインスタンス
"""
login_user_id = os.environ.get("ANNOFAB_USER_ID")
login_password = os.environ.get("ANNOFAB_PASSWORD")
if login_user_id is None or login_password is None:
raise AnnofabApiException("`ANNOFAB_USER_ID` or `ANNOFAB_PASSWORD` environment variable are empty.")

logger.debug("環境変数からAnnoFab認証情報を読み込みました。")
return Resource(login_user_id, login_password, endpoint_url=endpoint_url)
58 changes: 40 additions & 18 deletions annofabapi/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ def download_annotation_archive(self, project_id: str, dest_path: str) -> str:
_, response = self.api.get_annotation_archive(project_id, query_params=query_params)
url = response.headers["Location"]
response2 = _download(url, dest_path)
logger.debug(f"type=simple_annotation, Last-Modified={response2.headers.get('Last-Modified')}")
logger.debug(
f"project_id='{project_id}', type=simple_annotation, Last-Modified={response2.headers.get('Last-Modified')}"
)
return url

def download_full_annotation_archive(self, project_id: str, dest_path: str) -> str:
Expand All @@ -267,7 +269,9 @@ def download_full_annotation_archive(self, project_id: str, dest_path: str) -> s
_, response = self.api.get_archive_full_with_pro_id(project_id)
url = response.headers["Location"]
response2 = _download(url, dest_path)
logger.debug(f"type=full_annotation, Last-Modified={response2.headers.get('Last-Modified')}")
logger.debug(
f"project_id='{project_id}', type=full_annotation, Last-Modified={response2.headers.get('Last-Modified')}"
)
return url

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

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

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

except CheckSumError as e:
message = (
Expand Down Expand Up @@ -1574,7 +1578,9 @@ def download_project_inputs_url(self, project_id: str, dest_path: str) -> str:
content, _ = self.api.get_project_inputs_url(project_id)
url = content["url"]
response2 = _download(url, dest_path)
logger.debug(f"type=input_data, Last-Modified={response2.headers.get('Last-Modified')}")
logger.debug(
f"project_id='{project_id}', type=input_data, Last-Modified={response2.headers.get('Last-Modified')}"
)
return url

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

def download_project_inspections_url(self, project_id: str, dest_path: str) -> str:
Expand All @@ -1614,7 +1620,10 @@ def download_project_inspections_url(self, project_id: str, dest_path: str) -> s
content, _ = self.api.get_project_inspections_url(project_id)
url = content["url"]
response2 = _download(url, dest_path)
logger.debug(f"type=inspection_comment, Last-Modified={response2.headers.get('Last-Modified')}")
logger.debug(
f"project_id='{project_id}', type=inspection_comment,"
f"Last-Modified={response2.headers.get('Last-Modified')}"
)
return url

def download_project_task_history_events_url(self, project_id: str, dest_path: str) -> str:
Expand All @@ -1634,7 +1643,10 @@ def download_project_task_history_events_url(self, project_id: str, dest_path: s
content, _ = self.api.get_project_task_history_events_url(project_id)
url = content["url"]
response2 = _download(url, dest_path)
logger.debug(f"type=task_history_event, Last-Modified={response2.headers.get('Last-Modified')}")
logger.debug(
f"project_id='{project_id}', type=task_history_event, "
f"Last-Modified={response2.headers.get('Last-Modified')}"
)
return url

def download_project_task_histories_url(self, project_id: str, dest_path: str) -> str:
Expand All @@ -1654,7 +1666,9 @@ def download_project_task_histories_url(self, project_id: str, dest_path: str) -
content, _ = self.api.get_project_task_histories_url(project_id)
url = content["url"]
response2 = _download(url, dest_path)
logger.debug(f"type=task_history, Last-Modified={response2.headers.get('Last-Modified')}")
logger.debug(
f"project_id='{project_id}', type=task_history, Last-Modified={response2.headers.get('Last-Modified')}"
)
return url

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

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

if job is None:
logger.debug("job_id='%s', job_type='%s' のジョブは存在しません。", job_type.value, job_id)
logger.debug(
"project_id='%s', job_id='%s', job_type='%s' のジョブは存在しません。", project_id, job_type.value, job_id
)
return None

job_access_count += 1

if job["job_status"] == JobStatus.SUCCEEDED.value:
logger.debug("job_id='%s', job_type='%s' のジョブが成功しました。", job_id, job_type.value)
logger.debug(
"project_id='%s', job_id='%s', job_type='%s' のジョブが成功しました。", project_id, job_id, job_type.value
)
return JobStatus.SUCCEEDED

elif job["job_status"] == JobStatus.FAILED.value:
logger.debug("job_id='%s', job_type='%s' のジョブが失敗しました。", job_id, job_type.value)
logger.debug(
"project_id='%s', job_id='%s', job_type='%s' のジョブが失敗しました。", project_id, job_id, job_type.value
)
return JobStatus.FAILED

else:
# 進行中
if job_access_count < max_job_access:
logger.debug(
"job_id='%s', job_type='%s' のジョブは進行中です。%d 秒間待ちます。",
"project_id='%s', job_id='%s', job_type='%s' のジョブは進行中です。%d 秒間待ちます。",
project_id,
job_id,
job_type.value,
job_access_interval,
)
time.sleep(job_access_interval)
else:
logger.debug(
"job_id='%s', job_type='%s' のジョブは %.1f 分以上経過しても、終了しませんでした。",
"project_id='%s', job_id='%s', job_type='%s' のジョブは %.1f 分以上経過しても、終了しませんでした。",
project_id,
job["job_id"],
job_type.value,
job_access_interval * job_access_count / 60,
Expand Down Expand Up @@ -2407,7 +2429,7 @@ def _to_new_data(labor: Dict[str, Any]) -> Dict[str, Any]:
dt_new_to_date = dt_from_date + datetime.timedelta(days=diff_days // 2)
dt_new_from_date = dt_new_to_date + datetime.timedelta(days=1)
logger.debug(
"取得対象の期間が広すぎるため、データを取得できませんでした。"
f"project_id='{project_id}': 取得対象の期間が広すぎるため、データを取得できませんでした。"
f"取得対象の期間を{from_date}~{dt_new_to_date.strftime(DATE_FORMAT)}, "
f"{dt_new_from_date.strftime(DATE_FORMAT)}~{to_date}に分割して、再度取得します。"
)
Expand Down
2 changes: 1 addition & 1 deletion generate/partial-header/dataclass/job.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from annofabapi._utils import deprecated_class
from annofabapi.models import JobStatus, ProjectJobType
from annofabapi.models import JobStatus, ProjectJobType, Errors
4 changes: 4 additions & 0 deletions generate/swagger/swagger-api-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,8 @@ components:
job_detail:
type: object
description: ジョブ結果の内部情報
errors:
$ref: "#/components/schemas/Errors"
created_datetime:
type: string
format: date-time
Expand All @@ -1323,6 +1325,8 @@ components:
job_detail:
type: object
description: ジョブ結果の内部情報
errors:
$ref: "#/components/schemas/Errors"
created_datetime:
type: string
format: date-time
Expand Down
2 changes: 1 addition & 1 deletion generate/swagger/swagger.v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ info:
上記例 `account_id_count` は、タスクのフィールド `account_id` でタスクを分類したところ「`account_id` が `c5eee002` であるタスクが9件、`9f110e48` であるタスクが5件、`b25dfeb3` であるタスクが1件」だったという結果を表しています。
version: 0.125.0
version: 0.127.0
title: AnnoFab Web API
x-logo:
url: "https://annofab.com/resource/images/logo_landscape.png"
Expand Down
6 changes: 3 additions & 3 deletions generate/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ info:
上記例 `account_id_count` は、タスクのフィールド `account_id` でタスクを分類したところ「`account_id` が `c5eee002` であるタスクが9件、`9f110e48` であるタスクが5件、`b25dfeb3` であるタスクが1件」だったという結果を表しています。
また、AggregationResultの集約の件数は、合計で10000件以下に制限されており、それを超える件数がある場合は上位10000件が取得されます。もし、省略された部分を取得したい場合は、検索条件を縛って結果に上る集約の数を減らしてください。
version: 0.125.0
version: 0.127.0
title: AnnoFab Web API
x-logo:
url: "https://annofab.com/resource/images/logo_landscape.png"
Expand Down Expand Up @@ -3138,7 +3138,7 @@ paths:
default: 1
- name: exclusive_start_created_datetime
in: query
description: 取得するデータの直前の作成日時
description: 取得するデータの直前の作成日時(ISO 8601 拡張形式)
required: false
schema:
type: string
Expand Down Expand Up @@ -3207,7 +3207,7 @@ paths:
default: 1
- name: exclusive_start_created_datetime
in: query
description: 取得するデータの直前の作成日時
description: 取得するデータの直前の作成日時(ISO 8601 拡張形式)
required: false
schema:
type: string
Expand Down

0 comments on commit 756ad10

Please sign in to comment.