From 74edf16d14dd8077c6636cde032ec822b560518e Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 1 Oct 2024 18:44:51 +0530 Subject: [PATCH] Convert amounts to int for comparison --- .../webapp/handle_deployment_auction.py | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/stack_orchestrator/deploy/webapp/handle_deployment_auction.py b/stack_orchestrator/deploy/webapp/handle_deployment_auction.py index 19df4216..380e8b49 100644 --- a/stack_orchestrator/deploy/webapp/handle_deployment_auction.py +++ b/stack_orchestrator/deploy/webapp/handle_deployment_auction.py @@ -37,7 +37,7 @@ def process_app_deployment_auction( logger, ): # Fetch auction details - auction_id = request.auction + auction_id = request.attributes.auction auction = laconic.get_auction(auction_id) if not auction: raise Exception(f"Unable to locate auction: {auction_id}") @@ -49,30 +49,32 @@ def process_app_deployment_auction( if current_status == "PENDING": # Skip if pending auction not in commit state if auction.status != AuctionStatus.COMMIT: - logger(f"Skipping pending request, auction {auction_id} status: {auction.status}") + logger.log(f"Skipping pending request, auction {auction_id} status: {auction.status}") return "SKIP", "" # Check max_price - if auction.max_price < bid_amount: - logger(f"Skipping auction {auction_id} with max_price ({auction.max_price}) less than bid_amount {bid_amount}") + bid_amount_int = int(bid_amount) + max_price_int = int(auction.maxPrice.quantity) + if max_price_int < bid_amount_int: + logger.log(f"Skipping auction {auction_id} with max_price ({max_price_int}) less than bid_amount ({bid_amount_int})") return "SKIP", "" # Bid on the auction - reveal_file_path = laconic.commit_bid(auction_id, bid_amount) - logger(f"Commited bid on auction {auction_id} with amount {bid_amount}") + reveal_file_path = laconic.commit_bid(auction_id, bid_amount_int) + logger.log(f"Commited bid on auction {auction_id} with amount {bid_amount_int}") return "COMMIT", reveal_file_path if current_status == "COMMIT": # Return if auction still in commit state if auction.status == AuctionStatus.COMMIT: - logger(f"Auction {auction_id} status: {auction.status}") + logger.log(f"Auction {auction_id} status: {auction.status}") return current_status, reveal_file_path # Reveal bid if auction.status == AuctionStatus.REVEAL: laconic.reveal_bid(auction_id, reveal_file_path) - logger(f"Revealed bid on auction {auction_id}") + logger.log(f"Revealed bid on auction {auction_id}") return "REVEAL", reveal_file_path @@ -81,11 +83,12 @@ def process_app_deployment_auction( if current_status == "REVEAL": # Return if auction still in reveal state if auction.status == AuctionStatus.REVEAL: - logger(f"Auction {auction_id} status: {auction.status}") + logger.log(f"Auction {auction_id} status: {auction.status}") return current_status, reveal_file_path - # Return if auction still in completed state + # Return if auction is completed if auction.status == AuctionStatus.COMPLETED: + logger.log(f"Auction {auction_id} completed") return "COMPLETED", "" raise Exception(f"Unexpected auction {auction_id} status: {auction.status}") @@ -108,7 +111,9 @@ def dump_known_auction_requests(filename, requests, status="SEEN"): "--laconic-config", help="Provide a config file for laconicd", required=True ) @click.option( - "--state-file", help="File to store state about previously seen auction requests." + "--state-file", + help="File to store state about previously seen auction requests.", + required=True, ) @click.option( "--bid-amount", @@ -125,8 +130,8 @@ def command( state_file, bid_amount, dry_run, -): # noqa: C901 - if bid_amount < 0: +): + if int(bid_amount) < 0: print("--bid-amount cannot be less than 0", file=sys.stderr) sys.exit(2) @@ -137,9 +142,8 @@ def command( auctions_requests = laconic.app_deployment_auctions() previous_requests = {} - if state_file: - logger.log(f"Loading known auctions from {state_file}...") - previous_requests = load_known_requests(state_file) + logger.log(f"Loading known auctions from {state_file}...") + previous_requests = load_known_requests(state_file) # Process new requests first auctions_requests.sort(key=lambda r: r.createTime) @@ -180,15 +184,11 @@ def command( except Exception as e: result_status = "ERROR" - logger.log(f"ERROR examining request {r.id}: " + str(e)) + logger.log(f"ERROR: examining request {r.id}: " + str(e)) finally: - logger.log(f"DONE Examining request {r.id} with result {result_status}.") + logger.log(f"DONE: Examining request {r.id} with result {result_status}.") if result_status in ["ERROR"]: - dump_known_auction_requests( - state_file, - [AttrDict({"id": r.id, "revealFile": reveal_file_path})], - status=result_status - ) + dump_known_auction_requests(state_file, [AttrDict({"id": r.id, "revealFile": reveal_file_path})], result_status) logger.log(f"Found {len(requests_to_execute)} request(s) to process.")