From 0b93f32c34f2fc3f2e5c9e917a9eb86bd4fcd889 Mon Sep 17 00:00:00 2001 From: Marjorie Lucas Date: Wed, 10 Jul 2024 18:18:27 -0700 Subject: [PATCH 1/2] added pagination to listJobs endpoint --- maap/maap.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/maap/maap.py b/maap/maap.py index 993fa1c..9b3b4d0 100644 --- a/maap/maap.py +++ b/maap/maap.py @@ -256,10 +256,24 @@ def cancelJob(self, jobid): job.id = jobid return job.cancel_job() - def listJobs(self, username=None): + def listJobs(self, username=None, page_size=None, offset=None): if username==None and self.profile is not None and 'username' in self.profile.account_info().keys(): username = self.profile.account_info()['username'] - url = os.path.join(self.config.dps_job, username, endpoints.DPS_JOB_LIST) + + query_params = [] + if page_size is not None: + query_params.append(f"page_size={page_size}") + if offset is not None: + query_params.append(f"offset={offset}") + + query_string = "&".join(query_params) + + if query_string: + endpoint = endpoints.DPS_JOB_LIST + "?" + query_string + url = os.path.join(self.config.dps_job, username, endpoint) + else: + url = os.path.join(self.config.dps_job, username, endpoints.DPS_JOB_LIST) + headers = self._get_api_header() logger.debug('GET request sent to {}'.format(url)) logger.debug('headers:') From 471ce47b70392bfaf18ad24f1d85caf70063d637 Mon Sep 17 00:00:00 2001 From: Marjorie Lucas Date: Thu, 11 Jul 2024 08:53:59 -0700 Subject: [PATCH 2/2] change request --- maap/maap.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/maap/maap.py b/maap/maap.py index 9b3b4d0..8b91695 100644 --- a/maap/maap.py +++ b/maap/maap.py @@ -259,28 +259,18 @@ def cancelJob(self, jobid): def listJobs(self, username=None, page_size=None, offset=None): if username==None and self.profile is not None and 'username' in self.profile.account_info().keys(): username = self.profile.account_info()['username'] - - query_params = [] - if page_size is not None: - query_params.append(f"page_size={page_size}") - if offset is not None: - query_params.append(f"offset={offset}") - - query_string = "&".join(query_params) - - if query_string: - endpoint = endpoints.DPS_JOB_LIST + "?" + query_string - url = os.path.join(self.config.dps_job, username, endpoint) - else: - url = os.path.join(self.config.dps_job, username, endpoints.DPS_JOB_LIST) + url = os.path.join(self.config.dps_job, username, endpoints.DPS_JOB_LIST) + params = {k: v for k, v in (("page_size", page_size), ("offset", offset)) if v} + headers = self._get_api_header() logger.debug('GET request sent to {}'.format(url)) logger.debug('headers:') logger.debug(headers) response = requests.get( url=url, - headers=headers + headers=headers, + params=params, ) return response