Skip to content

Commit 8860600

Browse files
Merge pull request #195 from dashscope/dev/issues-9
fix(deployments): exit with error on deployment status check failure
1 parent 71e45a1 commit 8860600

12 files changed

Lines changed: 44 additions & 539 deletions

File tree

‎dashscope/cli/deployments.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ def _wait_for_deployment(
8585
except Exception as exc:
8686
logger.debug("wait_for_deployment error", exc_info=exc)
8787
err_console.print(
88+
f"[red]Error:[/red] Failed to check deployment status: {exc}. "
8889
f"You can get deployment status via: "
8990
f"[cyan]dashscope deployments get {deployed_model}[/cyan]",
9091
)
92+
raise typer.Exit(1)
9193

9294

9395
def _print_deployments(output):

‎dashscope/finetune/agentic_rl.py‎

Lines changed: 1 addition & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
# Copyright (c) Alibaba, Inc. and its affiliates.
55

6-
import time
76
from typing import Union, List, Optional, ClassVar, Dict, Any
87
from typing_extensions import Self
98

@@ -44,7 +43,6 @@
4443
from dashscope.finetune.reinforcement.common.errors import (
4544
RegistrationError,
4645
ValidationError,
47-
InstanceQueryError,
4846
RuntimeErrorWithCode,
4947
ValueErrorWithCode,
5048
DatasetsError,
@@ -428,28 +426,7 @@ async def test_functions(
428426
functype: FunctionType,
429427
input_data: Dict[str, Any],
430428
api_key: str = None,
431-
pull_logs: bool = False,
432-
log_page_size: int = 100,
433-
start_time: Optional[int] = None,
434-
end_time: Optional[int] = None,
435429
):
436-
"""Test a deployed function instance with custom input data.
437-
438-
Args:
439-
instance_id: Target function instance ID.
440-
functype: Function type (ROLLOUT/REWARD/GROUP_REWARD).
441-
input_data: Test input payload.
442-
api_key: DashScope API key (uses DASHSCOPE_API_KEY env var
443-
if omitted).
444-
pull_logs: If True, pull all logs of the function instance
445-
(with pagination) after verification and print them
446-
between separator markers.
447-
log_page_size: Page size used when pulling logs.
448-
start_time: Optional start time filter (in seconds) for log
449-
pulling. Defaults to 24 hours before ``end_time``.
450-
end_time: Optional end time filter (in seconds) for log
451-
pulling. Defaults to the current time (now).
452-
"""
453430
try:
454431
set_api_key(api_key)
455432

@@ -473,197 +450,13 @@ async def test_functions(
473450
},
474451
)
475452

476-
result = await AgenticRLFunctionComponent.verify_function(
453+
return await AgenticRLFunctionComponent.verify_function(
477454
value,
478455
instance_id,
479456
)
480457

481-
if pull_logs:
482-
await cls._pull_function_instance_logs(
483-
function_instance_id=instance_id,
484-
page_size=log_page_size,
485-
start_time=start_time,
486-
end_time=end_time,
487-
)
488-
489-
return result
490-
491458
except Exception as e:
492459
raise ValidationError(
493460
"Function test failed",
494461
error_code=3008,
495462
) from e
496-
497-
@classmethod
498-
async def query_function_instance_logs(
499-
cls,
500-
function_instance_id: str,
501-
page_number: int = 1,
502-
page_size: int = 100,
503-
start_time: Optional[int] = None,
504-
end_time: Optional[int] = None,
505-
keywords: Optional[List[str]] = None,
506-
api_key: str = None,
507-
) -> Dict[str, Any]:
508-
"""Query one page of logs for a function (faas) instance.
509-
510-
Args:
511-
function_instance_id: Target function instance ID.
512-
page_number: Page number, starting from 1.
513-
page_size: Number of log entries per page.
514-
start_time: Optional start time filter (in seconds).
515-
end_time: Optional end time filter (in seconds).
516-
keywords: Optional keyword filters for log messages.
517-
api_key: DashScope API key (uses DASHSCOPE_API_KEY env var
518-
if omitted).
519-
520-
Returns:
521-
Raw response dict of the log query API.
522-
"""
523-
try:
524-
set_api_key(api_key)
525-
526-
fc_component = AgenticRLFunctionComponent
527-
return await fc_component.query_function_instance_logs(
528-
function_instance_id=function_instance_id,
529-
page_number=page_number,
530-
page_size=page_size,
531-
start_time=start_time,
532-
end_time=end_time,
533-
keywords=keywords,
534-
)
535-
536-
except Exception as e:
537-
if hasattr(e, "error_code"):
538-
raise
539-
raise InstanceQueryError(
540-
"Function instance log query failed",
541-
error_code=3009,
542-
) from e
543-
544-
@classmethod
545-
async def query_all_function_instance_logs(
546-
cls,
547-
function_instance_id: str,
548-
page_size: int = 100,
549-
start_time: Optional[int] = None,
550-
end_time: Optional[int] = None,
551-
keywords: Optional[List[str]] = None,
552-
api_key: str = None,
553-
) -> List[str]:
554-
"""Fetch all logs of a function (faas) instance.
555-
556-
Pages are fetched one by one via the paginated log query until
557-
all entries are collected.
558-
559-
Args:
560-
function_instance_id: Target function instance ID.
561-
page_size: Number of log entries per page.
562-
start_time: Optional start time filter (in seconds).
563-
end_time: Optional end time filter (in seconds).
564-
keywords: Optional keyword filters for log messages.
565-
api_key: DashScope API key (uses DASHSCOPE_API_KEY env var
566-
if omitted).
567-
568-
Returns:
569-
Aggregated list of log messages across all pages.
570-
"""
571-
try:
572-
set_api_key(api_key)
573-
574-
fc_component = AgenticRLFunctionComponent
575-
return await fc_component.query_all_function_instance_logs(
576-
function_instance_id=function_instance_id,
577-
page_size=page_size,
578-
start_time=start_time,
579-
end_time=end_time,
580-
keywords=keywords,
581-
)
582-
583-
except Exception as e:
584-
if hasattr(e, "error_code"):
585-
raise
586-
raise InstanceQueryError(
587-
"Function instance log query failed",
588-
error_code=3010,
589-
) from e
590-
591-
@classmethod
592-
async def delete_function_instance(
593-
cls,
594-
function_instance_id: str,
595-
api_key: str = None,
596-
) -> Dict[str, Any]:
597-
"""Delete a function (faas) runtime instance.
598-
599-
Args:
600-
function_instance_id: Target function instance ID.
601-
api_key: DashScope API key (uses DASHSCOPE_API_KEY env var
602-
if omitted).
603-
604-
Returns:
605-
Raw response dict of the delete API, containing
606-
``data.status`` (e.g. "deleted") and
607-
``data.sandbox_code``.
608-
609-
Raises:
610-
InstanceQueryError: If the deletion fails.
611-
"""
612-
try:
613-
set_api_key(api_key)
614-
615-
fc_component = AgenticRLFunctionComponent
616-
return await fc_component.delete_function_instance(
617-
function_instance_id=function_instance_id,
618-
)
619-
620-
except Exception as e:
621-
if hasattr(e, "error_code"):
622-
raise
623-
raise InstanceQueryError(
624-
"Function instance deletion failed",
625-
error_code=3011,
626-
) from e
627-
628-
@classmethod
629-
async def _pull_function_instance_logs(
630-
cls,
631-
function_instance_id: str,
632-
page_size: int = 100,
633-
start_time: Optional[int] = None,
634-
end_time: Optional[int] = None,
635-
) -> None:
636-
"""Pull all logs of a function instance and print them between
637-
separator markers (best effort, never raises).
638-
639-
When ``start_time``/``end_time`` are not provided, defaults to
640-
pulling logs from 24 hours ago until now.
641-
"""
642-
if end_time is None:
643-
end_time = int(time.time())
644-
if start_time is None:
645-
start_time = end_time - 24 * 60 * 60
646-
logger.info(
647-
"************start query log "
648-
f"(function_instance_id={function_instance_id})*******",
649-
)
650-
try:
651-
logs = await cls.query_all_function_instance_logs(
652-
function_instance_id=function_instance_id,
653-
page_size=page_size,
654-
start_time=start_time,
655-
end_time=end_time,
656-
)
657-
for entry in logs:
658-
logger.info(f"[function instance log] {entry}")
659-
logger.info(
660-
f"Pulled {len(logs)} log entries for function instance "
661-
f"{function_instance_id}",
662-
)
663-
except Exception as e:
664-
logger.warning(
665-
f"Failed to pull logs for function instance "
666-
f"{function_instance_id}: {e}",
667-
)
668-
finally:
669-
logger.info("************end query log *******")

‎dashscope/finetune/deployments.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ def call( # pylint: disable=arguments-renamed # type: ignore[override]
4747
4848
Args:
4949
model (str): The model name.
50+
capacity (int): The model service capacity.
5051
version (str, optional): The model version, unnecessary
5152
for fine-tuned model. Defaults to None.
5253
suffix (str, optional): The name suffix of the model deployment,
5354
If specified, the final model name will be model_suffix.
5455
Defaults to None.
55-
capacity (int, optional): The model service capacity.
5656
plan (str, optional): The deployment plan required by the
5757
service: "ptu" (PTU reserved), "mu" (model unit) or
5858
"Lora" (LoRA deployment). Defaults to None.

‎dashscope/finetune/reinforcement/__init__.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
DASHSCOPE_HTTP_BASE_URL,
1717
LOG_LEVEL,
1818
FC_API_KEY,
19-
FC_DELETE_API,
2019
FC_FILES_START,
2120
FC_LOAD_API,
2221
FC_PYPI_LIB,
2322
FC_PYPI_REPO,
2423
FC_QUERY_API,
25-
FC_QUERY_LOG_API,
2624
FC_REGISTER_REWARD_API,
2725
FC_REGISTER_ROLLOUT_API,
2826
FC_REGISTER_GROUP_REWARD_API,
@@ -156,13 +154,11 @@ def __getattr__(name):
156154
"DASHSCOPE_HTTP_BASE_URL",
157155
"LOG_LEVEL",
158156
"FC_API_KEY",
159-
"FC_DELETE_API",
160157
"FC_FILES_START",
161158
"FC_LOAD_API",
162159
"FC_PYPI_LIB",
163160
"FC_PYPI_REPO",
164161
"FC_QUERY_API",
165-
"FC_QUERY_LOG_API",
166162
"FC_REGISTER_REWARD_API",
167163
"FC_REGISTER_ROLLOUT_API",
168164
"FC_REGISTER_GROUP_REWARD_API",

‎dashscope/finetune/reinforcement/common/constants.py‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,6 @@ def get_int_env(env_var: str, default: int) -> int:
8383
)
8484
FC_LOAD_API = os.environ.get("FC_LOAD_API", f"{FC_BASE_ENDPOINT}/online/faas")
8585
FC_QUERY_API = os.environ.get("FC_QUERY_API", f"{FC_BASE_ENDPOINT}/query/faas")
86-
FC_QUERY_LOG_API = os.environ.get(
87-
"FC_QUERY_LOG_API",
88-
f"{FC_BASE_ENDPOINT}/query/faas/log",
89-
)
90-
FC_DELETE_API = os.environ.get(
91-
"FC_DELETE_API",
92-
f"{FC_BASE_ENDPOINT}/delete/faas",
93-
)
9486
FC_LAYER_CREATE_API = os.environ.get( # POST
9587
"FC_LAYER_CREATE_API",
9688
f"{FC_BASE_ENDPOINT}/create/faas/layer",

0 commit comments

Comments
 (0)