From ccad068a484b11a86e402d433639e10213dd58fc Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Wed, 24 Jul 2019 14:56:17 +0100 Subject: [PATCH] Change when 'has-jobs-<>' cache key gets set We should set the cache after the job has been created, in case there was an HTTP error when creating the job. --- app/notify_client/job_api_client.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/notify_client/job_api_client.py b/app/notify_client/job_api_client.py index 16f104409..20999b949 100644 --- a/app/notify_client/job_api_client.py +++ b/app/notify_client/job_api_client.py @@ -97,12 +97,6 @@ class JobApiClient(NotifyAdminAPIClient): return bool(self.get_jobs(service_id)['data']) def create_job(self, job_id, service_id, scheduled_for=None): - redis_client.set( - 'has_jobs-{}'.format(service_id), - b'true', - ex=cache.TTL, - ) - data = {"id": job_id} if scheduled_for: @@ -111,6 +105,12 @@ class JobApiClient(NotifyAdminAPIClient): data = _attach_current_user(data) job = self.post(url='/service/{}/job'.format(service_id), data=data) + redis_client.set( + 'has_jobs-{}'.format(service_id), + b'true', + ex=cache.TTL, + ) + stats = self.__convert_statistics(job['data']) job['data']['notifications_sent'] = stats['delivered'] + stats['failed'] job['data']['notifications_delivered'] = stats['delivered']