@@ -185,8 +185,8 @@ async def execute(
185185
186186 Args:
187187 device: 目标设备
188- command: 要执行的命令 (Pull操作)
189- config: 要推送的配置 (Push操作)
188+ command: 要执行的命令 (Pull操作)
189+ config: 要推送的配置 (Push操作)
190190 parse_with: 解析器类型
191191 save: 是否保存配置
192192 dry_run: 是否为干运行模式
@@ -229,9 +229,15 @@ async def execute(
229229 }
230230
231231 if parse_with :
232+ cmd_or_cfg = command or config
233+ template_name = (
234+ cmd_or_cfg .replace (" " , "_" )
235+ if isinstance (cmd_or_cfg , str )
236+ else cmd_or_cfg [0 ].replace (" " , "_" )
237+ )
232238 options ["parsing" ] = {
233239 "name" : parse_with ,
234- "template" : f"file:///templates/{ ( command or config ). replace ( ' ' , '_' ) if isinstance (( command or config ), str ) else ( command or config )[ 0 ]. replace ( ' ' , '_' ) } .{ parse_with } " ,
240+ "template" : f"file:///templates/{ template_name } .{ parse_with } " ,
235241 }
236242
237243 # 创建请求
@@ -317,8 +323,8 @@ async def bulk(
317323
318324 Args:
319325 devices: 设备列表
320- command: 要执行的命令 (Pull操作)
321- config: 要推送的配置 (Push操作)
326+ command: 要执行的命令 (Pull操作)
327+ config: 要推送的配置 (Push操作)
322328 parse_with: 解析器类型
323329 save: 是否保存配置
324330 dry_run: 是否为干运行模式
@@ -373,9 +379,15 @@ async def bulk(
373379 }
374380
375381 if parse_with :
382+ cmd_or_cfg = command or config
383+ template_name = (
384+ cmd_or_cfg .replace (" " , "_" )
385+ if isinstance (cmd_or_cfg , str )
386+ else cmd_or_cfg [0 ].replace (" " , "_" )
387+ )
376388 options ["parsing" ] = {
377389 "name" : parse_with ,
378- "template" : f"file:///templates/{ ( command or config ). replace ( ' ' , '_' ) if isinstance (( command or config ), str ) else ( command or config )[ 0 ]. replace ( ' ' , '_' ) } .{ parse_with } " ,
390+ "template" : f"file:///templates/{ template_name } .{ parse_with } " ,
379391 }
380392
381393 # 创建请求
@@ -722,14 +734,16 @@ async def _wait_for_result_with_progressive_retry(
722734 """
723735 异步激进递进式重试等待任务结果
724736
725- 轮询策略:
737+ 轮询策略:
726738 - 初始延迟: 0.4秒
727- - 递增步长序列: 0.1s -> 0.2s -> 0.3s -> 0.5s -> 1.5s -> 2.5s -> 4.0s -> 6.0s -> 9.0s -> 13.5s -> 20.0s -> 30.0s
728- - 轮询间隔: 0.4s -> 0.5s -> 0.7s -> 1.0s -> 1.5s -> 3.0s -> 5.5s -> 9.5s -> 15.5s -> 24.5s -> 37.5s -> 57.5s
739+ - 递增步长序列: 0.1s -> 0.2s -> 0.3s -> 0.5s -> 1.5s -> 2.5s -> 4.0s
740+ -> 6.0s -> 9.0s -> 13.5s -> 20.0s -> 30.0s
741+ - 轮询间隔: 0.4s -> 0.5s -> 0.7s -> 1.0s -> 1.5s -> 3.0s -> 5.5s
742+ -> 9.5s -> 15.5s -> 24.5s -> 37.5s -> 57.5s
729743 - 最大间隔: 30秒
730744 - 最大总时长: 120秒
731745
732- 示例轮询序列:
746+ 示例轮询序列:
733747 第1次: 0.4s (初始)
734748 第2次: 0.5s (0.4s + 0.1s)
735749 第3次: 0.7s (0.5s + 0.2s)
@@ -766,16 +780,19 @@ async def _wait_for_result_with_progressive_retry(
766780
767781 if status in ["finished" , "failed" ]:
768782 logger .info (
769- f"任务 { job_id } 完成, 总耗时: { total_elapsed :.2f} 秒, 轮询次数: { attempt } "
783+ f"任务 { job_id } 完成, 总耗时: { total_elapsed :.2f} 秒, "
784+ f"轮询次数: { attempt } "
770785 )
771786 return result
772787 elif status == "queued" :
773788 logger .info (
774- f"任务 { job_id } 排队中... (第{ attempt } 次轮询, 已耗时{ total_elapsed :.2f} 秒)"
789+ f"任务 { job_id } 排队中... "
790+ f"(第{ attempt } 次轮询, 已耗时{ total_elapsed :.2f} 秒)"
775791 )
776792 elif status == "started" :
777793 logger .info (
778- f"任务 { job_id } 执行中... (第{ attempt } 次轮询, 已耗时{ total_elapsed :.2f} 秒)"
794+ f"任务 { job_id } 执行中... "
795+ f"(第{ attempt } 次轮询, 已耗时{ total_elapsed :.2f} 秒)"
779796 )
780797
781798 # 激进递进式延迟
@@ -796,7 +813,8 @@ async def _wait_for_result_with_progressive_retry(
796813 # 记录轮询信息
797814 if attempt % 3 == 0 : # 每3次轮询记录一次详细信息
798815 logger .info (
799- f"任务 { job_id } 轮询中... 第{ attempt } 次, 当前延迟: { delay :.2f} s, 总耗时: { total_elapsed :.2f} s"
816+ f"任务 { job_id } 轮询中... 第{ attempt } 次, "
817+ f"当前延迟: { delay :.2f} s, 总耗时: { total_elapsed :.2f} s"
800818 )
801819
802820 except Exception as e :
0 commit comments