mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-11 08:43:47 -04:00
make dashboard jobs list hit job api twice
once for scheduled jobs, once for past jobs this ensures that if you have lots of scheduled jobs it can still return your last 50 jobs
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
from datetime import datetime, timedelta
|
||||
from collections import namedtuple
|
||||
from itertools import groupby
|
||||
|
||||
import dateutil
|
||||
from flask import (
|
||||
@@ -20,7 +18,7 @@ from app import (
|
||||
service_api_client,
|
||||
template_statistics_client
|
||||
)
|
||||
from app.statistics_utils import add_rates_to, get_formatted_percentage, add_rate_to_jobs
|
||||
from app.statistics_utils import get_formatted_percentage, add_rate_to_job
|
||||
from app.utils import user_has_permissions
|
||||
|
||||
|
||||
@@ -117,20 +115,26 @@ def aggregate_usage(template_statistics):
|
||||
|
||||
|
||||
def get_dashboard_partials(service_id):
|
||||
# all but scheduled and cancelled
|
||||
statuses_to_display = [
|
||||
'pending',
|
||||
'in progress',
|
||||
'finished',
|
||||
'sending limits exceeded',
|
||||
]
|
||||
|
||||
template_statistics = aggregate_usage(
|
||||
template_statistics_client.get_template_statistics_for_service(service_id, limit_days=7)
|
||||
)
|
||||
|
||||
jobs = add_rate_to_jobs([
|
||||
job for job in job_api_client.get_jobs(service_id, limit_days=7)['data']
|
||||
if job['original_file_name'] != current_app.config['TEST_MESSAGE_FILENAME']
|
||||
])
|
||||
scheduled_jobs = sorted([
|
||||
job for job in jobs if job['job_status'] == 'scheduled'
|
||||
], key=lambda job: job['scheduled_for'])
|
||||
scheduled_jobs = sorted(
|
||||
job_api_client.get_jobs(service_id, statuses=['scheduled'])['data'],
|
||||
key=lambda job: job['scheduled_for']
|
||||
)
|
||||
immediate_jobs = [
|
||||
job for job in jobs if job['job_status'] not in ['scheduled', 'cancelled']
|
||||
add_rate_to_job(job)
|
||||
for job in job_api_client.get_jobs(service_id, statuses=statuses_to_display)['data']
|
||||
if job['original_file_name'] != current_app.config['TEST_MESSAGE_FILENAME']
|
||||
]
|
||||
service = service_api_client.get_detailed_service(service_id)
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ from app.utils import (
|
||||
generate_previous_next_dict,
|
||||
user_has_permissions,
|
||||
generate_notifications_csv)
|
||||
from app.statistics_utils import add_rate_to_jobs
|
||||
from app.utils import get_help_argument
|
||||
|
||||
|
||||
@@ -67,10 +66,10 @@ def _set_status_filters(filter_args):
|
||||
def view_jobs(service_id):
|
||||
return render_template(
|
||||
'views/jobs/jobs.html',
|
||||
jobs=add_rate_to_jobs([
|
||||
job for job in job_api_client.get_jobs(service_id)['data']
|
||||
jobs=[
|
||||
add_rate_to_job(job) for job in job_api_client.get_jobs(service_id)['data']
|
||||
if job['job_status'] not in ['scheduled', 'cancelled']
|
||||
])
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -901,7 +901,7 @@ def mock_get_job_in_progress(mocker, api_user_active):
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_jobs(mocker, api_user_active):
|
||||
def _get_jobs(service_id, limit_days=None):
|
||||
def _get_jobs(service_id, limit_days=None, statuses=None):
|
||||
return {"data": [
|
||||
job_json(
|
||||
service_id,
|
||||
|
||||
Reference in New Issue
Block a user