Skip to content

ジョブが進行中かどうかを表すメソッドjob_in_progressメソッドを追加する #105

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 12 commits into from
Jan 9, 2020
Merged
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ lint:
pipenv run pylint annofabapi --rcfile setup.cfg

test:
pipenv run pytest tests -v --cov=annofabapi --cov-report=html
pipenv run pytest tests -rs -v --cov=annofabapi --cov-report=html

publish_test:
rm -fr build/ dist/ annofabapi.egg-info
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.24.0'
__version__ = '0.24.1'
29 changes: 25 additions & 4 deletions annofabapi/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from annofabapi import AnnofabApi
from annofabapi.exceptions import AnnofabApiException
from annofabapi.models import (AnnotationSpecsV1, InputData, Inspection, InspectionStatus, Instruction, JobInfo,
JobType, MyOrganization, Organization, OrganizationMember, Project, ProjectMember,
SupplementaryData, Task)
JobStatus, JobType, MyOrganization, Organization, OrganizationMember, Project,
ProjectMember, SupplementaryData, Task)
from annofabapi.utils import allow_404_error

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -615,6 +615,8 @@ def put_project_members(self, project_id, project_members: List[Dict[str, Any]])
request_body = {
"member_status": member["member_status"],
"member_role": member["member_role"],
"sampling_inspection_rate": member.get("sampling_inspection_rate"),
"sampling_acceptance_rate": member.get("sampling_acceptance_rate"),
"last_updated_datetime": last_updated_datetime,
}
updated_project_member = self.api.put_project_member(project_id, member["user_id"],
Expand Down Expand Up @@ -770,7 +772,7 @@ def get_all_tasks(self, project_id: str, query_params: Optional[Dict[str, Any]]
return self._get_all_objects(self.api.get_tasks, limit=200, project_id=project_id, query_params=query_params)

#########################################
# Public Method : AfInstructionApi
# Public Method : Instruction
#########################################
def get_latest_instruction(self, project_id: str) -> Optional[Instruction]:
"""
Expand Down Expand Up @@ -826,7 +828,7 @@ def upload_instruction_image(self, project_id: str, image_id: str, file_path: st
return content["path"]

#########################################
# Public Method : AfJobApi
# Public Method : Job
#########################################
def delete_all_succeeded_job(self, project_id: str, job_type: JobType) -> List[JobInfo]:
"""
Expand Down Expand Up @@ -876,6 +878,25 @@ def get_all_project_job(self, project_id: str, query_params: Dict[str, Any]) ->
all_jobs.extend(r["list"])
return all_jobs

def job_in_progress(self, project_id: str, job_type: JobType) -> bool:
"""
ジョブが進行中かどうか

Args:
project_id: プロジェクトID
job_type: ジョブ種別

Returns:
True: ジョブが進行中かどうか

"""
job_list = self.api.get_project_job(project_id, query_params={"type": job_type.value})[0]["list"]
if len(job_list) == 0:
return False

job = job_list[0]
return job["job_status"] == JobStatus.PROGRESS.value

def wait_for_completion(self, project_id: str, job_type: JobType, job_access_interval: int = 60,
max_job_access: int = 10) -> bool:
"""
Expand Down
Loading