Skip to content

[wrapper.wait_for_completion] メソッドの修正 #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 19, 2019
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ format:
pipenv run yapf --verbose --in-place --recursive annofabapi tests

lint:
pipenv run flake8 annofabapi
pipenv run mypy annofabapi --config-file setup.cfg
pipenv run flake8 annofabapi
pipenv run pylint annofabapi --rcfile setup.cfg

test:
Expand Down
2 changes: 1 addition & 1 deletion annofabapi/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.21.2'
__version__ = '0.21.3'
18 changes: 12 additions & 6 deletions annofabapi/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,17 +803,23 @@ def wait_for_completion(self, project_id: str, job_type: JobType, job_access_int
Falseならば、ジョブが失敗 or ``max_job_access`` 回アクセスしても、ジョブが完了しなかった。

"""
def get_latest_job():
def get_latest_job() -> Optional[JobInfo]:
job_list = self.api.get_project_job(project_id, query_params={"type": job_type.value})[0]["list"]
assert len(job_list) == 1
return job_list[0]
if len(job_list) > 0:
return job_list[0]
else:
return None

job_access_count = 0
while True:
job = get_latest_job()
if job_access_count == 0 and job["job_status"] != "progress":
logger.debug("進行中のジョブはありませんでした。")
if job is None:
logger.debug("ジョブは存在しませんでした。")
return True
else:
if job_access_count == 0 and job["job_status"] != "progress":
logger.debug("進行中のジョブはありませんでした。")
return True

job_access_count += 1

Expand All @@ -831,5 +837,5 @@ def get_latest_job():
logger.debug("job_id = %s のジョブが進行中です。%d 秒間待ちます。", job['job_id'], job_access_interval)
time.sleep(job_access_interval)
else:
logger.debug("job_id = %s のジョブに %d 回アクセスしましたが、完了しませんでした。", job['job_id'], job_access_interval)
logger.debug("job_id = %s のジョブに %d 回アクセスしましたが、完了しませんでした。", job['job_id'], job_access_count)
return False