Skip to content

Commit

Permalink
15818 NAMES/Society Restoration Incorrect Expire Date (#1383)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
eve-git authored Oct 4, 2023
1 parent 841ccc3 commit 2b1f760
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 37 deletions.
1 change: 0 additions & 1 deletion jobs/nro-update/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
11 changes: 1 addition & 10 deletions jobs/nro-update/nro/nro_datapump.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
37 changes: 19 additions & 18 deletions jobs/nro-update/nro_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,16 @@ 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
# #########################################

# 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
Expand Down Expand Up @@ -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')

Expand Down
5 changes: 0 additions & 5 deletions jobs/nro-update/openshift/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions jobs/nro-update/tests/test_nro_datapump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2b1f760

Please sign in to comment.