From 2b1f760c579a2f0cb5aca3537b1a83c1e0b364a7 Mon Sep 17 00:00:00 2001 From: eve-git <54647458+eve-git@users.noreply.github.com> Date: Wed, 4 Oct 2023 15:42:58 -0700 Subject: [PATCH] 15818 NAMES/Society Restoration Incorrect Expire Date (#1383) * remove environment config EXPIRES_DAYS * add log * fixing the error InstrumentedList object has no attribute 'all' * fixing the error InstrumentedList object has no attribute 'all' * fixing the error InstrumentedList object has no attribute 'all' * revert the changes in nro-extractor * remove a debug --- jobs/nro-update/config.py | 1 - jobs/nro-update/nro/nro_datapump.py | 11 +----- jobs/nro-update/nro_update.py | 37 ++++++++++--------- .../openshift/templates/deployment.yaml | 5 --- jobs/nro-update/tests/test_nro_datapump.py | 7 ++-- 5 files changed, 24 insertions(+), 37 deletions(-) diff --git a/jobs/nro-update/config.py b/jobs/nro-update/config.py index e136203c9..d85ef19c6 100644 --- a/jobs/nro-update/config.py +++ b/jobs/nro-update/config.py @@ -10,7 +10,6 @@ class Config(object): MAX_ROW_LIMIT = os.getenv('MAX_ROWS','100') MIN_DELAY_SECONDS = os.getenv('MIN_DELAY_SECONDS','600') - EXPIRES_DAYS = os.getenv('EXPIRES_DAYS','60') NRO_SERVICE_ACCOUNT = os.getenv('NRO_SERVICE_ACCOUNT', 'nro_service_account') diff --git a/jobs/nro-update/nro/nro_datapump.py b/jobs/nro-update/nro/nro_datapump.py index 0ee242de9..863ff84e2 100644 --- a/jobs/nro-update/nro/nro_datapump.py +++ b/jobs/nro-update/nro/nro_datapump.py @@ -1,21 +1,12 @@ from datetime import timedelta, datetime from flask import current_app from pytz import timezone -import pytz from namex.models import Name, State -from namex.services.name_request import NameRequestService from namex.services.nro.utils import nro_examiner_name -def nro_data_pump_update(nr, ora_cursor, expires_days=56): - nr_service = NameRequestService() - expiry_date = nr_service.create_expiry_date( - start=nr.lastUpdate, - expires_in_days=expires_days - ) - - current_app.logger.debug(f'Setting expiry date to: { expiry_date }') +def nro_data_pump_update(nr, ora_cursor, expiry_date): # init dict for examiner comment data, populated below in loop through names examiner_comment = { 'choice': 0, diff --git a/jobs/nro-update/nro_update.py b/jobs/nro-update/nro_update.py index e1d11ca05..a630dc354 100644 --- a/jobs/nro-update/nro_update.py +++ b/jobs/nro-update/nro_update.py @@ -27,13 +27,8 @@ def get_ops_params(): max_rows = int(current_app.config.get('MAX_ROW_LIMIT', 1000)) except: max_rows = 1000 - try: - expires_days = int(current_app.config.get('EXPIRES_DAYS', 60)) - except: - expires_days=60 - - return delay, max_rows, expires_days + return delay, max_rows # #### Send the NameX Request info to NRO @@ -41,7 +36,7 @@ def get_ops_params(): # this allows me to use the NameX ORM Model, and use the db scoped session attached to the models. app = create_app(Config) -delay, max_rows, expires_days = get_ops_params() +delay, max_rows = get_ops_params() start_time = datetime.utcnow() row_count = 0 @@ -80,28 +75,34 @@ def get_ops_params(): compile_kwargs={"literal_binds": True})) ) - for r in q.all(): - row_count += 1 + nr_service = NameRequestService() - current_app.logger.debug('processing: {}'.format(r.nrNum)) + for nr in q.all(): + row_count += 1 + current_app.logger.debug('processing: {}'.format(nr.nrNum)) try: - nr_service = NameRequestService() - expiry_days = int(nr_service.get_expiry_days(r)) - nro_data_pump_update(r, ora_cursor, expiry_days) - db.session.add(r) - EventRecorder.record(user, Event.NRO_UPDATE, r, r.json(), save_to_session=True) + expiry_days = int(nr_service.get_expiry_days(nr)) + expiry_date = nr_service.create_expiry_date( + start=nr.lastUpdate, + expires_in_days=expiry_days + ) + current_app.logger.debug(f'Setting expiry date to: { expiry_date }') + + nro_data_pump_update(nr, ora_cursor, expiry_date) + db.session.add(nr) + EventRecorder.record(user, Event.NRO_UPDATE, nr, nr.json(), save_to_session=True) ora_con.commit() db.session.commit() - JobTracker.job_detail(db, job_id, r.nrNum) + JobTracker.job_detail(db, job_id, nr.nrNum) except Exception as err: current_app.logger.error(err) - current_app.logger.error('ERROR: {}'.format(r.nrNum)) + current_app.logger.error('ERROR: {}'.format(nr.nrNum)) db.session.rollback() ora_con.rollback() - JobTracker.job_detail_error(db, job_id, r.nrNum, str(err)) + JobTracker.job_detail_error(db, job_id, nr.nrNum, str(err)) JobTracker.end_job(db, job_id, datetime.utcnow(), 'success') diff --git a/jobs/nro-update/openshift/templates/deployment.yaml b/jobs/nro-update/openshift/templates/deployment.yaml index 5ddab3fc0..5e4a92660 100644 --- a/jobs/nro-update/openshift/templates/deployment.yaml +++ b/jobs/nro-update/openshift/templates/deployment.yaml @@ -75,11 +75,6 @@ objects: secretKeyRef: name: ${NAME}-${TAG}-secret key: MIN_DELAY_SECONDS - - name: EXPIRES_DAYS - valueFrom: - secretKeyRef: - name: ${NAME}-${TAG}-secret - key: EXPIRES_DAYS - name: ORA_PORT valueFrom: secretKeyRef: diff --git a/jobs/nro-update/tests/test_nro_datapump.py b/jobs/nro-update/tests/test_nro_datapump.py index c90c0a085..c668df8f2 100644 --- a/jobs/nro-update/tests/test_nro_datapump.py +++ b/jobs/nro-update/tests/test_nro_datapump.py @@ -61,9 +61,9 @@ def test_datapump(app, mocker, start_date, expected_date): # mock the oracle cursor oc = mocker.MagicMock() - # make the real call - nro_data_pump_update(nr, ora_cursor=oc, expires_days=56) + # make the real call + nro_data_pump_update(nr, ora_cursor=oc, expiry_date=datetime(2023, 6, 30, 23, 59)) oc.callfunc.assert_called_with('NRO_DATAPUMP_PKG.name_examination_func', # package.func_name str, ['NR 0000001', # p_nr_number @@ -120,7 +120,8 @@ def test_datapump_nr_requires_consent_flag(app, mocker,consent_flag,state_cd): # mock the oracle cursor oc = mocker.MagicMock() # make the real call - nro_data_pump_update(nr, ora_cursor=oc, expires_days=60) + + nro_data_pump_update(nr, ora_cursor=oc, expiry_date=datetime(2023, 6, 30, 23, 59)) oc.callfunc.assert_called_with('NRO_DATAPUMP_PKG.name_examination_func', # package.func_name str,