generated from cfpb/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
173 multithread submission processing (#174)
Closes #173 Closes #181 - Added the multithread_handler.py to handle creating the event loop, and monitoring the future from the process executor - Added the ProcessPoolExecutor stuff to the submission POST. I was not able to get this working in its own class/function for some reason, I had to add this stuff for the executor and background task directly to the endpoint. Otherwise, the execution task never fired. - Added pytests --------- Co-authored-by: lchen-2101 <73617864+lchen-2101@users.noreply.github.com>
- Loading branch information
1 parent
cf26810
commit 0ddf51b
Showing
12 changed files
with
241 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import asyncio | ||
import logging | ||
|
||
from sbl_filing_api.config import settings | ||
from sbl_filing_api.entities.models.dao import SubmissionDAO | ||
from sbl_filing_api.entities.repos import submission_repo as repo | ||
from sbl_filing_api.services.submission_processor import validate_and_update_submission | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def handle_submission(period_code: str, lei: str, submission: SubmissionDAO, content: bytes, exec_check): | ||
loop = asyncio.get_event_loop() | ||
try: | ||
coro = validate_and_update_submission(period_code, lei, submission, content, exec_check) | ||
loop.run_until_complete(coro) | ||
except Exception as e: | ||
logger.error(e, exc_info=True, stack_info=True) | ||
|
||
|
||
async def check_future(future, submission_id, exec_check): | ||
await asyncio.sleep(settings.expired_submission_check_secs) | ||
if not future.done(): | ||
future.cancel() | ||
exec_check["continue"] = False | ||
await repo.expire_submission(submission_id) | ||
logger.warning( | ||
f"Validation for submission {submission_id} did not complete within the expected timeframe, will be set to VALIDATION_EXPIRED." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.