-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CV2-3551 add local queue consumption and re-work a ton of the startup flow to accommodate #33
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dd26eb7
CV2-3551 add local queue consumption and re-work a ton of the startup…
DGaffney 0097b88
more fixes after running end to end locally
DGaffney 75aec61
update tests
DGaffney 928481c
rename fingerprinting to process
DGaffney 76c819e
add required field
DGaffney 3eb7947
fix test condition
DGaffney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
.PHONY: run run_http run_worker run_test | ||
|
||
run: | ||
./start_healthcheck_and_model_engine.sh | ||
./start_all.sh | ||
|
||
run_http: | ||
uvicorn main:app --host 0.0.0.0 --reload | ||
|
||
run_worker: | ||
python run.py | ||
python run_worker.py | ||
|
||
run_processor: | ||
python run_processor.py | ||
|
||
run_test: | ||
python -m unittest discover . | ||
python -m pytest test |
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
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,57 @@ | ||
from typing import List | ||
import json | ||
|
||
import requests | ||
|
||
from lib import schemas | ||
from lib.logger import logger | ||
from lib.helpers import get_setting | ||
from lib.queue.queue import Queue | ||
class QueueProcessor(Queue): | ||
@classmethod | ||
def create(cls, input_queue_name: str = None, batch_size: int = 10): | ||
""" | ||
Instantiate a queue. Must pass input_queue_name, output_queue_name, and batch_size. | ||
Pulls settings and then inits instance. | ||
""" | ||
input_queue_name = get_setting(input_queue_name, "MODEL_NAME").replace(".", "__") | ||
logger.info(f"Starting queue with: ('{input_queue_name}', {batch_size})") | ||
return QueueProcessor(input_queue_name, batch_size) | ||
|
||
def __init__(self, input_queue_name: str, output_queue_name: str = None, batch_size: int = 1): | ||
""" | ||
Start a specific queue - must pass input_queue_name - optionally pass output_queue_name, batch_size. | ||
""" | ||
super().__init__() | ||
self.input_queue_name = input_queue_name | ||
self.input_queues = self.restrict_queues_to_suffix(self.get_or_create_queues(input_queue_name+"_output"), "_output") | ||
self.all_queues = self.store_queue_map(self.input_queues) | ||
logger.info(f"Processor listening to queues of {self.all_queues}") | ||
self.batch_size = batch_size | ||
|
||
def send_callbacks(self) -> List[schemas.Message]: | ||
""" | ||
Main routine. Given a model, in a loop, read tasks from input_queue_name at batch_size depth, | ||
pass messages to model to respond (i.e. fingerprint) them, then pass responses to output queue. | ||
If failures happen at any point, resend failed messages to input queue. | ||
""" | ||
messages_with_queues = self.receive_messages(self.batch_size) | ||
if messages_with_queues: | ||
logger.debug(f"About to respond to: ({messages_with_queues})") | ||
bodies = [schemas.Message(**json.loads(message.body)) for message, queue in messages_with_queues] | ||
for body in bodies: | ||
self.send_callback(body) | ||
self.delete_messages(messages_with_queues) | ||
|
||
|
||
def send_callback(self, message): | ||
""" | ||
Rescue against failures when attempting to respond (i.e. fingerprint) from models. | ||
Return responses if no failure. | ||
""" | ||
logger.info(f"Message for callback is: {message}") | ||
try: | ||
callback_url = message.body.callback_url | ||
requests.post(callback_url, json=message.dict()) | ||
except Exception as e: | ||
logger.error(f"Callback fail! Failed with {e} on {callback_url} with message of {message}") |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not in this PR, but we should probably call this in parallel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cosign