Skip to content
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

Release 0.13.1 #280

Merged
merged 8 commits into from
Jun 6, 2024
15 changes: 11 additions & 4 deletions iap/api/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ def request_product(receipt_data: ReceiptSchema,


@router.post("/free", response_model=ReceiptDetailSchema)
def free_product(receipt_data: FreeReceiptSchema, sess=Depends(session)):
def free_product(receipt_data: FreeReceiptSchema,
x_iap_packagename: Annotated[PackageName | None, Header()] = PackageName.NINE_CHRONICLES_M,
sess=Depends(session)):
"""
# Purchase Free Product
---
Expand All @@ -376,12 +378,17 @@ def free_product(receipt_data: FreeReceiptSchema, sess=Depends(session)):
.options(joinedload(Product.fav_list)).options(joinedload(Product.fungible_item_list))
.where(
Product.active.is_(True),
or_(Product.google_sku == receipt_data.sku, Product.apple_sku == receipt_data.sku)
or_(
Product.google_sku == receipt_data.sku,
Product.apple_sku == receipt_data.sku,
Product.apple_sku_k == receipt_data.sku
)
)
)
order_id = f"FREE-{uuid4()}"
receipt = Receipt(
store=receipt_data.store,
package_name=x_iap_packagename.value,
data={"SKU": receipt_data.sku, "OrderId": order_id},
agent_addr=receipt_data.agentAddress.lower(),
avatar_addr=receipt_data.avatarAddress.lower(),
Expand All @@ -397,8 +404,8 @@ def free_product(receipt_data: FreeReceiptSchema, sess=Depends(session)):
# Validation
if not product:
receipt.status = ReceiptStatus.INVALID
receipt.msg = f"Product {receipt_data.product_id} not exists or inactive"
raise_error(sess, receipt, ValueError(f"Product {receipt_data.product_id} not found or inactive"))
receipt.msg = f"Product {receipt_data.sku} not exists or inactive"
raise_error(sess, receipt, ValueError(f"Product {receipt_data.sku} not found or inactive"))

if not product.is_free:
receipt.status = ReceiptStatus.INVALID
Expand Down
12 changes: 12 additions & 0 deletions worker/worker/lambda_warmer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import requests

from common import logger


def heat(event, context):
timeout = 1
try:
resp = requests.get("https://iap-internal.9c.gg/ping?from=warmer", timeout=timeout)
print(resp.text)
except requests.exceptions.Timeout:
logger.error(f"Ping timed out after {timeout} seconds!")
16 changes: 16 additions & 0 deletions worker/worker_cdk_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,19 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
environment=env,
memory_size=512,
)

lambda_warmer = _lambda.Function(
self, f"{config.stage}-9c-iap-lambda-warmer",
function_name=f"{config.stage}-9c-iap-lambda-warmer",
runtime=_lambda.Runtime.PYTHON_3_10,
description=f"Warm lambda instance to response fast",
code=_lambda.AssetCode("worker/worker", exclude=exclude_list),
handler="lambda_warmer.heat",
layers=[layer],
role=role,
vpc=shared_stack.vpc,
timeout=cdk_core.Duration.seconds(10),
environment=env,
memory_size=128,
)
minute_event_rule.add_target(_event_targets.LambdaFunction(lambda_warmer))
Loading