Skip to content

Commit de7c377

Browse files
authored
Merge pull request #90 from kurusugawa-computer/fix/wait-method
[wrapper.wait_for_completion] メソッドの修正
2 parents 6f844ad + 14d85f9 commit de7c377

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ format:
1010
pipenv run yapf --verbose --in-place --recursive annofabapi tests
1111

1212
lint:
13-
pipenv run flake8 annofabapi
1413
pipenv run mypy annofabapi --config-file setup.cfg
14+
pipenv run flake8 annofabapi
1515
pipenv run pylint annofabapi --rcfile setup.cfg
1616

1717
test:

annofabapi/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.21.2'
1+
__version__ = '0.21.3'

annofabapi/wrapper.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -803,17 +803,23 @@ def wait_for_completion(self, project_id: str, job_type: JobType, job_access_int
803803
Falseならば、ジョブが失敗 or ``max_job_access`` 回アクセスしても、ジョブが完了しなかった。
804804
805805
"""
806-
def get_latest_job():
806+
def get_latest_job() -> Optional[JobInfo]:
807807
job_list = self.api.get_project_job(project_id, query_params={"type": job_type.value})[0]["list"]
808-
assert len(job_list) == 1
809-
return job_list[0]
808+
if len(job_list) > 0:
809+
return job_list[0]
810+
else:
811+
return None
810812

811813
job_access_count = 0
812814
while True:
813815
job = get_latest_job()
814-
if job_access_count == 0 and job["job_status"] != "progress":
815-
logger.debug("進行中のジョブはありませんでした。")
816+
if job is None:
817+
logger.debug("ジョブは存在しませんでした。")
816818
return True
819+
else:
820+
if job_access_count == 0 and job["job_status"] != "progress":
821+
logger.debug("進行中のジョブはありませんでした。")
822+
return True
817823

818824
job_access_count += 1
819825

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

0 commit comments

Comments
 (0)