Skip to content

Commit

Permalink
22204 Filer + Dissolutions Job - Updated to support queued status (bc…
Browse files Browse the repository at this point in the history
…gov#2903)

* Track batch processing status from filer

* Undo makefile changes

* Fix lint

* Undo makefile change

* Add unit tests

* Update unit tests

* Move step change back to job

* Fix alembic downgrade

* Fix unit test

* Use filing id

* Add filing_id to unit test

* Grab filing id from filing_rec

* Save filing before putting on filer queue
  • Loading branch information
leodube-aot authored Aug 14, 2024
1 parent 3eb435c commit a6b4779
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 15 deletions.
15 changes: 9 additions & 6 deletions jobs/involuntary-dissolutions/involuntary_dissolutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,19 +279,22 @@ async def stage_3_process(app: Flask, qsm: QueueService):
if eligible:
filing = create_invountary_dissolution_filing(batch_processing.business_id)
app.logger.debug(f'Created Involuntary Dissolution Filing with ID: {filing.id}')
await put_filing_on_queue(filing.id, app, qsm)

batch_processing.filing_id = filing.id
batch_processing.step = BatchProcessing.BatchProcessingStep.DISSOLUTION
batch_processing.status = BatchProcessing.BatchProcessingStatus.COMPLETED
batch_processing.status = BatchProcessing.BatchProcessingStatus.QUEUED
batch_processing.last_modified = datetime.utcnow()
batch_processing.save()

await put_filing_on_queue(filing.id, app, qsm)

app.logger.debug(
f'Batch Processing with identifier: {batch_processing.business_identifier} has been marked as complete.'
f'Batch Processing with identifier: {batch_processing.business_identifier} has been marked as queued.'
)
else:
batch_processing.status = BatchProcessing.BatchProcessingStatus.WITHDRAWN
batch_processing.notes = 'Moved back into good standing'
batch_processing.last_modified = datetime.utcnow()
batch_processing.save()
batch_processing.last_modified = datetime.utcnow()
batch_processing.save()

mark_eligible_batches_completed()
app.logger.debug('Marked batches complete when all of their associated batch_processings are completed.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def test_stage_2_process_update_business(app, session, test_name, status, step):
'test_name, status, step', [
(
'DISSOLVE_BUSINESS',
BatchProcessing.BatchProcessingStatus.COMPLETED,
BatchProcessing.BatchProcessingStatus.QUEUED,
BatchProcessing.BatchProcessingStep.DISSOLUTION
),
(
Expand Down Expand Up @@ -317,8 +317,9 @@ async def test_stage_3_process(app, session, test_name, status, step):
if test_name == 'DISSOLVE_BUSINESS':
mock_put_filing_on_queue.assert_called()
assert batch_processing.filing_id
assert batch.status == Batch.BatchStatus.PROCESSING
else:
assert batch.status == Batch.BatchStatus.COMPLETED

assert batch_processing.status == status
assert batch_processing.step == step

assert batch.status == Batch.BatchStatus.COMPLETED
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def upgrade():

def downgrade():
# Need to convert any existing QUEUED statuses to PROCESSING
op.execute('UPDATE batch_processing SET status = "PROCESSED" WHERE status = "QUEUED"')
op.execute('UPDATE batch_processing SET status = \'PROCESSING\' WHERE status = \'QUEUED\'')
op.execute('ALTER TYPE batch_processing_status RENAME TO tmp_batch_processing_status')
old_type.create(op.get_bind())
op.execute('ALTER TABLE batch_processing ALTER COLUMN status TYPE batch_processing_status USING status::text::batch_processing_status')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
import dpath
import sentry_sdk
from entity_queue_common.service_utils import QueueException, logger
from legal_api.models import Business, Document, Filing, db
from legal_api.models import BatchProcessing, Business, Document, Filing, db
from legal_api.models.document import DocumentType
from legal_api.services.filings.validations.dissolution import DissolutionTypes
from legal_api.services.minio import MinioService
from legal_api.services.pdf_service import RegistrarStampData
from legal_api.utils.datetime import datetime
from legal_api.utils.legislation_datetime import LegislationDatetime

from entity_filer.filing_meta import FilingMeta
Expand All @@ -31,7 +32,8 @@
from entity_filer.utils import replace_file_with_certified_copy


def process(business: Business, filing: Dict, filing_rec: Filing, filing_meta: FilingMeta):
# pylint: disable=too-many-locals
def process(business: Business, filing: Dict, filing_rec: Filing, filing_meta: FilingMeta, flag_on: bool = False):
"""Render the dissolution filing unto the model objects."""
if not (dissolution_filing := filing.get('dissolution')):
logger.error('Could not find Dissolution in: %s', filing)
Expand Down Expand Up @@ -95,6 +97,15 @@ def process(business: Business, filing: Dict, filing_rec: Filing, filing_meta: F
'dissolutionDate': LegislationDatetime.format_as_legislation_date(business.dissolution_date)
}

# update batch processing entry, if any is present
if flag_on:
batch_processings = BatchProcessing.find_by(filing_id=filing_rec.id)
for batch_processing in batch_processings:
if batch_processing.status == BatchProcessing.BatchProcessingStatus.QUEUED:
batch_processing.status = BatchProcessing.BatchProcessingStatus.COMPLETED
batch_processing.last_modified = datetime.utcnow()
batch_processing.save()


def _update_cooperative(dissolution_filing: Dict, business: Business, filing: Filing, dissolution_type):
"""Update COOP data.
Expand Down
3 changes: 2 additions & 1 deletion queue_services/entity-filer/src/entity_filer/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ async def process_filing(filing_msg: Dict, flask_app: Flask): # pylint: disable
change_of_name.process(business, filing, filing_meta)

elif filing.get('dissolution'):
dissolution.process(business, filing, filing_submission, filing_meta)
flag_on = flags.is_on('enable-involuntary-dissolution')
dissolution.process(business, filing, filing_submission, filing_meta, flag_on)

elif filing.get('incorporationApplication'):
business, filing_submission, filing_meta = incorporation_filing.process(business,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
# limitations under the License.
"""The Unit Tests for the Voluntary Dissolution filing."""
import copy
from datedelta import datedelta
from datetime import datetime

import pytest

from legal_api.models import Business, Office, OfficeType, Party, PartyRole, Filing
from legal_api.models import BatchProcessing, Batch, Business, Office, OfficeType, Party, PartyRole, Filing
from legal_api.models.document import DocumentType
from legal_api.services.minio import MinioService
from legal_api.utils.legislation_datetime import LegislationDatetime
Expand Down Expand Up @@ -98,8 +99,28 @@ def test_dissolution(app, session, minio_server, legal_type, identifier, dissolu
filing_meta = FilingMeta()
filing = create_filing('123', filing_json)

if dissolution_type == 'involuntary':
batch = Batch(
batch_type=Batch.BatchType.INVOLUNTARY_DISSOLUTION,
status=Batch.BatchStatus.PROCESSING,
size=1,
)
batch.save()
batch_processing = BatchProcessing(
batch_id=batch.id,
business_id=business.id,
filing_id=filing.id,
business_identifier=business.identifier,
step=BatchProcessing.BatchProcessingStep.DISSOLUTION,
status=BatchProcessing.BatchProcessingStatus.QUEUED,
created_date=datetime.utcnow()-datedelta(days=42),
trigger_date=datetime.utcnow(),
last_modified=datetime.utcnow()
)
batch_processing.save()

# test
dissolution.process(business, filing_json['filing'], filing, filing_meta)
dissolution.process(business, filing_json['filing'], filing, filing_meta, True)
business.save()

# validate
Expand Down Expand Up @@ -127,6 +148,9 @@ def test_dissolution(app, session, minio_server, legal_type, identifier, dissolu
assert_pdf_contains_text('Filed on ', affidavit_obj.read())

assert filing_meta.dissolution['dissolutionType'] == dissolution_type
if dissolution_type == 'involuntary':
assert batch_processing
assert batch_processing.status == BatchProcessing.BatchProcessingStatus.COMPLETED

expected_dissolution_date = filing.effective_date
if dissolution_type == 'voluntary' and business.legal_type in (Business.LegalTypes.SOLE_PROP.value,
Expand Down

0 comments on commit a6b4779

Please sign in to comment.