mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
Merge pull request #899 from alphagov/handle-new-jobs-api
Handle new jobs api
This commit is contained in:
@@ -78,13 +78,12 @@ def view_job(service_id, job_id):
|
||||
filter_args = _parse_filter_args(request.args)
|
||||
filter_args['status'] = _set_status_filters(filter_args)
|
||||
|
||||
total_notifications = job.get('notification_count', 0)
|
||||
processed_notifications = job.get('notifications_delivered', 0) + job.get('notifications_failed', 0)
|
||||
|
||||
return render_template(
|
||||
'views/jobs/job.html',
|
||||
finished=job.get('notifications_sent', 0) and ((
|
||||
job.get('notifications_sent', 0) -
|
||||
job.get('notifications_delivered', 0) -
|
||||
job.get('notifications_failed', 0)
|
||||
) == 0),
|
||||
finished=(total_notifications == processed_notifications),
|
||||
uploaded_file_name=job['original_file_name'],
|
||||
template=Template(
|
||||
service_api_client.get_service_template(
|
||||
|
||||
@@ -14,15 +14,40 @@ class JobApiClient(BaseAPIClient):
|
||||
self.client_id = app.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.secret = app.config['ADMIN_CLIENT_SECRET']
|
||||
|
||||
@staticmethod
|
||||
def __convert_statistics(job):
|
||||
results = {
|
||||
'sending': 0,
|
||||
'delivered': 0,
|
||||
'failed': 0
|
||||
}
|
||||
if 'statistics' in job['data']:
|
||||
for outcome in job['data']['statistics']:
|
||||
if outcome['status'] in ['failed', 'technical-failure', 'temporary-failure', 'permanent-failure']:
|
||||
results['failed'] += outcome['count']
|
||||
if outcome['status'] in ['sending', 'pending', 'created']:
|
||||
results['sending'] += outcome['count']
|
||||
if outcome['status'] in ['delivered']:
|
||||
results['delivered'] += outcome['count']
|
||||
return results
|
||||
|
||||
def get_job(self, service_id, job_id=None, limit_days=None, status=None):
|
||||
if job_id:
|
||||
params = {}
|
||||
if status is not None:
|
||||
params['status'] = status
|
||||
return self.get(url='/service/{}/job/{}'.format(service_id, job_id), params=params)
|
||||
job = self.get(url='/service/{}/job/{}'.format(service_id, job_id), params=params)
|
||||
if 'notifications_sent' not in job['data']:
|
||||
stats = self.__convert_statistics(job)
|
||||
job['data']['notifications_sent'] = stats['delivered'] + stats['failed']
|
||||
job['data']['notifications_delivered'] = stats['delivered']
|
||||
job['data']['notifications_failed'] = stats['failed']
|
||||
return job
|
||||
|
||||
params = {}
|
||||
if limit_days is not None:
|
||||
params['limit_days'] = limit_days
|
||||
|
||||
return self.get(url='/service/{}/job'.format(service_id), params=params)
|
||||
|
||||
def create_job(self, job_id, service_id, template_id, original_file_name, notification_count):
|
||||
@@ -33,5 +58,12 @@ class JobApiClient(BaseAPIClient):
|
||||
"notification_count": notification_count
|
||||
}
|
||||
data = _attach_current_user(data)
|
||||
resp = self.post(url='/service/{}/job'.format(service_id), data=data)
|
||||
return resp['data']
|
||||
job = self.post(url='/service/{}/job'.format(service_id), data=data)
|
||||
|
||||
if 'notifications_sent' not in job['data']:
|
||||
stats = self.__convert_statistics(job)
|
||||
job['data']['notifications_sent'] = stats['delivered'] + stats['failed']
|
||||
job['data']['notifications_delivered'] = stats['delivered']
|
||||
job['data']['notifications_failed'] = stats['failed']
|
||||
|
||||
return job
|
||||
|
||||
Reference in New Issue
Block a user