diff --git a/app/celery/scheduled_tasks.py b/app/celery/scheduled_tasks.py index c8154721d..2e0413fe8 100644 --- a/app/celery/scheduled_tasks.py +++ b/app/celery/scheduled_tasks.py @@ -392,7 +392,7 @@ def check_job_status(): jobs_not_complete_after_30_minutes = Job.query.filter( Job.job_status == JOB_STATUS_IN_PROGRESS, and_(thirty_five_minutes_ago < Job.processing_started, Job.processing_started < thirty_minutes_ago) - ).all() + ).order_by(Job.processing_started).all() job_ids = [str(x.id) for x in jobs_not_complete_after_30_minutes] if job_ids: diff --git a/app/celery/tasks.py b/app/celery/tasks.py index f4218f5d9..f3244edb5 100644 --- a/app/celery/tasks.py +++ b/app/celery/tasks.py @@ -209,7 +209,7 @@ def send_sms(self, notification_type=SMS_TYPE, api_key_id=api_key_id, key_type=key_type, - created_at=created_at, + created_at=datetime.utcnow(), job_id=notification.get('job', None), job_row_number=notification.get('row_number', None), notification_id=notification_id @@ -254,7 +254,7 @@ def send_email(self, notification_type=EMAIL_TYPE, api_key_id=api_key_id, key_type=key_type, - created_at=created_at, + created_at=datetime.utcnow(), job_id=notification.get('job', None), job_row_number=notification.get('row_number', None), notification_id=notification_id @@ -295,7 +295,7 @@ def persist_letter( notification_type=LETTER_TYPE, api_key_id=None, key_type=KEY_TYPE_NORMAL, - created_at=created_at, + created_at=datetime.utcnow(), job_id=notification['job'], job_row_number=notification['row_number'], notification_id=notification_id, diff --git a/tests/app/celery/test_scheduled_tasks.py b/tests/app/celery/test_scheduled_tasks.py index ba87a94de..a61c70807 100644 --- a/tests/app/celery/test_scheduled_tasks.py +++ b/tests/app/celery/test_scheduled_tasks.py @@ -831,6 +831,6 @@ def test_check_job_status_task_raises_job_incomplete_error_for_multiple_jobs(moc mock_celery.assert_called_once_with( name=TaskNames.PROCESS_INCOMPLETE_JOBS, - args=([str(job_2.id), str(job.id)],), + args=([str(job.id), str(job_2.id)],), queue=QueueNames.JOBS ) diff --git a/tests/app/celery/test_tasks.py b/tests/app/celery/test_tasks.py index c4c5d1bd1..6841f69e7 100644 --- a/tests/app/celery/test_tasks.py +++ b/tests/app/celery/test_tasks.py @@ -700,7 +700,7 @@ def test_should_send_sms_template_to_and_persist_with_job_id(sample_job, sample_ assert persisted_notification.template_id == sample_job.template.id assert persisted_notification.status == 'created' assert not persisted_notification.sent_at - assert persisted_notification.created_at <= now + assert persisted_notification.created_at >= now assert not persisted_notification.sent_by assert persisted_notification.job_row_number == 2 assert persisted_notification.api_key_id == sample_api_key.id @@ -794,7 +794,7 @@ def test_should_use_email_template_and_persist(sample_email_template_with_placeh assert persisted_notification.to == 'my_email@my_email.com' assert persisted_notification.template_id == sample_email_template_with_placeholders.id assert persisted_notification.template_version == sample_email_template_with_placeholders.version - assert persisted_notification.created_at == now + assert persisted_notification.created_at >= now assert not persisted_notification.sent_at assert persisted_notification.status == 'created' assert not persisted_notification.sent_by @@ -831,7 +831,7 @@ def test_send_email_should_use_template_version_from_job_not_latest(sample_email assert persisted_notification.to == 'my_email@my_email.com' assert persisted_notification.template_id == sample_email_template.id assert persisted_notification.template_version == version_on_notification - assert persisted_notification.created_at == now + assert persisted_notification.created_at >= now assert not persisted_notification.sent_at assert persisted_notification.status == 'created' assert not persisted_notification.sent_by @@ -857,7 +857,7 @@ def test_should_use_email_template_subject_placeholders(sample_email_template_wi assert persisted_notification.to == 'my_email@my_email.com' assert persisted_notification.template_id == sample_email_template_with_placeholders.id assert persisted_notification.status == 'created' - assert persisted_notification.created_at == now + assert persisted_notification.created_at >= now assert not persisted_notification.sent_by assert persisted_notification.personalisation == {"name": "Jo"} assert not persisted_notification.reference @@ -883,7 +883,7 @@ def test_should_use_email_template_and_persist_without_personalisation(sample_em persisted_notification = Notification.query.one() assert persisted_notification.to == 'my_email@my_email.com' assert persisted_notification.template_id == sample_email_template.id - assert persisted_notification.created_at == now + assert persisted_notification.created_at >= now assert not persisted_notification.sent_at assert persisted_notification.status == 'created' assert not persisted_notification.sent_by @@ -1019,7 +1019,7 @@ def test_persist_letter_saves_letter_to_database(sample_letter_job, mocker): assert notification_db.template_id == sample_letter_job.template.id assert notification_db.template_version == sample_letter_job.template.version assert notification_db.status == 'created' - assert notification_db.created_at == created_at + assert notification_db.created_at >= created_at assert notification_db.notification_type == 'letter' assert notification_db.sent_at is None assert notification_db.sent_by is None