Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8aa4ea7342 |
@@ -69,6 +69,19 @@ class _Base:
|
|||||||
views.invalidate_task_list_count_cache()
|
views.invalidate_task_list_count_cache()
|
||||||
self.session.close()
|
self.session.close()
|
||||||
|
|
||||||
|
def complete_customer_profile(self, task: PlatformFulfillmentTask) -> None:
|
||||||
|
task.customer_role_name = "小淋笨"
|
||||||
|
task.customer_platform = "wechat"
|
||||||
|
task.customer_system = "android"
|
||||||
|
task.customer_home_images = [
|
||||||
|
{
|
||||||
|
"url": "https://example.com/game-home.png",
|
||||||
|
"thumbnailUrl": "https://example.com/game-home-thumb.png",
|
||||||
|
"objectKey": "game-home.png",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
self.session.commit()
|
||||||
|
|
||||||
def account(
|
def account(
|
||||||
self,
|
self,
|
||||||
name: str,
|
name: str,
|
||||||
@@ -3732,6 +3745,7 @@ class TestBindingAndCompletion(_Base):
|
|||||||
|
|
||||||
def test_customer_start_queues_allocation_without_sync_network(self, monkeypatch):
|
def test_customer_start_queues_allocation_without_sync_network(self, monkeypatch):
|
||||||
task = self.task()
|
task = self.task()
|
||||||
|
self.complete_customer_profile(task)
|
||||||
calls: list[list[int]] = []
|
calls: list[list[int]] = []
|
||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
"web.backend.services.platform_fulfillment.auto_allocator.wake_auto_allocator",
|
"web.backend.services.platform_fulfillment.auto_allocator.wake_auto_allocator",
|
||||||
@@ -3753,6 +3767,7 @@ class TestBindingAndCompletion(_Base):
|
|||||||
|
|
||||||
def test_customer_start_creates_one_binding_task_and_links_platform(self, monkeypatch):
|
def test_customer_start_creates_one_binding_task_and_links_platform(self, monkeypatch):
|
||||||
task = self._allocated()
|
task = self._allocated()
|
||||||
|
self.complete_customer_profile(task)
|
||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
service.binding,
|
service.binding,
|
||||||
"enqueue_execution_job",
|
"enqueue_execution_job",
|
||||||
@@ -3778,6 +3793,7 @@ class TestBindingAndCompletion(_Base):
|
|||||||
|
|
||||||
def test_customer_started_binding_does_not_capture_request_loop(self, monkeypatch):
|
def test_customer_started_binding_does_not_capture_request_loop(self, monkeypatch):
|
||||||
task = self._allocated()
|
task = self._allocated()
|
||||||
|
self.complete_customer_profile(task)
|
||||||
captured: dict[str, object] = {}
|
captured: dict[str, object] = {}
|
||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
service.binding,
|
service.binding,
|
||||||
@@ -3790,6 +3806,17 @@ class TestBindingAndCompletion(_Base):
|
|||||||
assert captured["job_type"] == "douyu_binding"
|
assert captured["job_type"] == "douyu_binding"
|
||||||
assert captured["batch_id"].startswith(f"pfbind-{task.id}-")
|
assert captured["batch_id"].startswith(f"pfbind-{task.id}-")
|
||||||
|
|
||||||
|
def test_customer_start_requires_game_home_profile(self):
|
||||||
|
task = self._allocated()
|
||||||
|
|
||||||
|
with pytest.raises(HTTPException) as exc_info:
|
||||||
|
asyncio.run(
|
||||||
|
service.customer_start_binding(self.session, task_id=task.id)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert exc_info.value.status_code == 409
|
||||||
|
assert "游戏主页截图" in str(exc_info.value.detail)
|
||||||
|
|
||||||
def test_concurrent_start_binding_creates_one_task(self, monkeypatch):
|
def test_concurrent_start_binding_creates_one_task(self, monkeypatch):
|
||||||
task = self._allocated()
|
task = self._allocated()
|
||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ from datetime import UTC, datetime, timedelta
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from sqlalchemy import or_
|
from sqlalchemy import func, or_
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from ...database import WorkerSessionLocal
|
from ...database import WorkerSessionLocal
|
||||||
from ...models import PlatformFulfillmentTask
|
from ...models import PlatformFulfillmentTask
|
||||||
from . import service
|
from . import service
|
||||||
from .common import FLOW_VERSION_CLEAN
|
from .common import FLOW_VERSION_CLEAN, _has_game_home_profile
|
||||||
|
|
||||||
DEFAULT_INTERVAL_SECONDS = 20
|
DEFAULT_INTERVAL_SECONDS = 20
|
||||||
DEFAULT_MIN_INTERVAL_SECONDS = 5
|
DEFAULT_MIN_INTERVAL_SECONDS = 5
|
||||||
@@ -194,6 +194,8 @@ def run_auto_allocation_once(
|
|||||||
if allocated_task is not None:
|
if allocated_task is not None:
|
||||||
allocated_task.next_allocate_at = None
|
allocated_task.next_allocate_at = None
|
||||||
db.commit()
|
db.commit()
|
||||||
|
if not _has_game_home_profile(allocated_task):
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
service.start_binding_sync(
|
service.start_binding_sync(
|
||||||
db,
|
db,
|
||||||
@@ -280,6 +282,10 @@ def start_allocated_bindings_once(
|
|||||||
PlatformFulfillmentTask.binding_status == "not_started",
|
PlatformFulfillmentTask.binding_status == "not_started",
|
||||||
PlatformFulfillmentTask.account_id.isnot(None),
|
PlatformFulfillmentTask.account_id.isnot(None),
|
||||||
PlatformFulfillmentTask.lease_id.isnot(None),
|
PlatformFulfillmentTask.lease_id.isnot(None),
|
||||||
|
PlatformFulfillmentTask.customer_role_name != "",
|
||||||
|
PlatformFulfillmentTask.customer_platform != "",
|
||||||
|
PlatformFulfillmentTask.customer_system != "",
|
||||||
|
func.json_length(PlatformFulfillmentTask.customer_home_images) > 0,
|
||||||
)
|
)
|
||||||
.order_by(
|
.order_by(
|
||||||
PlatformFulfillmentTask.updated_at.asc(), PlatformFulfillmentTask.id.asc()
|
PlatformFulfillmentTask.updated_at.asc(), PlatformFulfillmentTask.id.asc()
|
||||||
@@ -292,6 +298,8 @@ def start_allocated_bindings_once(
|
|||||||
actor = service._integration_actor(db)
|
actor = service._integration_actor(db)
|
||||||
started = 0
|
started = 0
|
||||||
for task in rows:
|
for task in rows:
|
||||||
|
if not _has_game_home_profile(task):
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
service.start_binding_sync(
|
service.start_binding_sync(
|
||||||
db,
|
db,
|
||||||
|
|||||||
@@ -141,6 +141,21 @@ def _order_snapshot_from_event(payload: dict[str, Any]) -> dict[str, Any]:
|
|||||||
return data if isinstance(data, dict) else payload
|
return data if isinstance(data, dict) else payload
|
||||||
|
|
||||||
|
|
||||||
|
def _has_game_home_profile(task: PlatformFulfillmentTask) -> bool:
|
||||||
|
"""Clean 任务必须同时有游戏角色、登录方式、系统和至少一张主页截图。"""
|
||||||
|
images = task.customer_home_images or []
|
||||||
|
return bool(
|
||||||
|
str(task.customer_role_name or "").strip()
|
||||||
|
and str(task.customer_platform or "").strip() in {"wechat", "qq"}
|
||||||
|
and str(task.customer_system or "").strip() in {"ios", "android"}
|
||||||
|
and isinstance(images, list)
|
||||||
|
and any(
|
||||||
|
isinstance(item, dict) and str(item.get("url") or "").strip()
|
||||||
|
for item in images
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _order_match_started_at(db: Session) -> datetime | None:
|
def _order_match_started_at(db: Session) -> datetime | None:
|
||||||
row = (
|
row = (
|
||||||
db.query(PlatformFulfillmentSetting)
|
db.query(PlatformFulfillmentSetting)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ from .binding import (
|
|||||||
refresh_binding,
|
refresh_binding,
|
||||||
start_binding,
|
start_binding,
|
||||||
)
|
)
|
||||||
|
from .common import FLOW_VERSION_CLEAN, _has_game_home_profile
|
||||||
from .order_sync import sync_order_item_ids
|
from .order_sync import sync_order_item_ids
|
||||||
from .repository import (
|
from .repository import (
|
||||||
_find_customer_task,
|
_find_customer_task,
|
||||||
@@ -126,6 +127,8 @@ async def customer_start_binding(
|
|||||||
return customer_binding_out(db, task.id)
|
return customer_binding_out(db, task.id)
|
||||||
if task.issue_code == "mapping_missing":
|
if task.issue_code == "mapping_missing":
|
||||||
return customer_binding_out(db, task.id)
|
return customer_binding_out(db, task.id)
|
||||||
|
if task.flow_version == FLOW_VERSION_CLEAN and not _has_game_home_profile(task):
|
||||||
|
raise HTTPException(status_code=409, detail="请先提交游戏角色和游戏主页截图")
|
||||||
|
|
||||||
if not task.account_id or not task.lease_id:
|
if not task.account_id or not task.lease_id:
|
||||||
from .auto_allocator import wake_auto_allocator
|
from .auto_allocator import wake_auto_allocator
|
||||||
|
|||||||
Reference in New Issue
Block a user