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.
This commit is contained in:
Katie Smith
2019-07-24 14:56:17 +01:00
parent dc1c73c647
commit ccad068a48

View File

@@ -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']