From c33c7a5058640deb9ade13299b5608952b7cd5bb Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 31 Oct 2024 11:48:08 -0700 Subject: [PATCH] fix more --- .ds.baseline | 4 ++-- app/celery/scheduled_tasks.py | 15 +++++++-------- tests/app/user/test_rest.py | 14 +++++++++----- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/.ds.baseline b/.ds.baseline index eb730eedd..bcae9f1e8 100644 --- a/.ds.baseline +++ b/.ds.baseline @@ -349,7 +349,7 @@ "filename": "tests/app/user/test_rest.py", "hashed_secret": "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33", "is_verified": false, - "line_number": 822, + "line_number": 826, "is_secret": false } ], @@ -384,5 +384,5 @@ } ] }, - "generated_at": "2024-10-31T18:32:23Z" + "generated_at": "2024-10-31T18:48:03Z" } diff --git a/app/celery/scheduled_tasks.py b/app/celery/scheduled_tasks.py index 504b77f56..86d801f88 100644 --- a/app/celery/scheduled_tasks.py +++ b/app/celery/scheduled_tasks.py @@ -105,24 +105,23 @@ def check_job_status(): thirty_minutes_ago = utc_now() - timedelta(minutes=30) thirty_five_minutes_ago = utc_now() - timedelta(minutes=35) - stmt = select(Job).where( + incomplete_in_progress_jobs = select(Job).where( Job.job_status == JobStatus.IN_PROGRESS, between(Job.processing_started, thirty_five_minutes_ago, thirty_minutes_ago), ) - incomplete_in_progress_jobs = db.session.execute(stmt).scalars().all() + # incomplete_in_progress_jobs = db.session.execute(stmt).scalars().all() - stmt = select(Job).where( + incomplete_pending_jobs = select(Job).where( Job.job_status == JobStatus.PENDING, Job.scheduled_for.isnot(None), between(Job.scheduled_for, thirty_five_minutes_ago, thirty_minutes_ago), ) - incomplete_pending_jobs = db.session.execute(stmt).scalars().all() + # incomplete_pending_jobs = db.session.execute(stmt).scalars().all() - jobs_not_complete_after_30_minutes = ( - incomplete_in_progress_jobs.union(incomplete_pending_jobs) - .order_by(Job.processing_started, Job.scheduled_for) - .all() + stmt = incomplete_in_progress_jobs.union(incomplete_pending_jobs).order_by( + Job.processing_started, Job.scheduled_for ) + jobs_not_complete_after_30_minutes = db.session.execute(stmt).scalars().all() # temporarily mark them as ERROR so that they don't get picked up by future check_job_status tasks # if they haven't been re-processed in time. diff --git a/tests/app/user/test_rest.py b/tests/app/user/test_rest.py index 399b708c6..f1ea5041b 100644 --- a/tests/app/user/test_rest.py +++ b/tests/app/user/test_rest.py @@ -336,7 +336,8 @@ def test_post_user_attribute_with_updated_by_sends_notification_to_international _data=update_dict, ) - notification = Notification.query.first() + stmt = select(Notification) + notification = db.session.execute(stmt).scalars().first() assert ( notification.reply_to_text == current_app.config["NOTIFY_INTERNATIONAL_SMS_SENDER"] @@ -526,7 +527,9 @@ def test_set_user_permissions_remove_old(admin_request, sample_user, sample_serv ) count = db.session.execute(query).scalar() or 0 assert count == 1 - assert query.first().permission == PermissionType.MANAGE_SETTINGS + query = select(Permission).where(Permission.user == sample_user) + first_permission = db.session.execute(query).scalars().first() + assert first_permission.permission == PermissionType.MANAGE_SETTINGS def test_set_user_folder_permissions(admin_request, sample_user, sample_service): @@ -658,7 +661,8 @@ def test_send_already_registered_email( _expected_status=204, ) - notification = Notification.query.first() + stmt = select(Notification) + notification = db.session.execute(stmt).scalars().first() mocked.assert_called_once_with( ([str(notification.id)]), queue="notify-internal-tasks" ) @@ -696,8 +700,8 @@ def test_send_user_confirm_new_email_returns_204( _data=data, _expected_status=204, ) - - notification = Notification.query.first() + stmt = select(Notification) + notification = db.session.execute(stmt).scalars().first() mocked.assert_called_once_with( ([str(notification.id)]), queue="notify-internal-tasks" )