Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
doudian-py
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
baiquan
doudian-py
Commits
dd7b0757
Commit
dd7b0757
authored
Jul 21, 2025
by
baiquan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(upload): 优化 SKU 图片上传的超时设置
- 将超时时间从 65 秒调整为 85 秒 - 优化超时计算逻辑,确保整个上传过程不超过设定的超时时间 -调整代码结构,提高可读性和维护性
parent
5afcfd97
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
service/upload_image_and_video.py
+6
-4
No files found.
service/upload_image_and_video.py
View file @
dd7b0757
...
@@ -197,6 +197,9 @@ async def uploadImageAndVideo(task: dict = None):
...
@@ -197,6 +197,9 @@ async def uploadImageAndVideo(task: dict = None):
error_msg
=
""
error_msg
=
""
# 准备SKU图片上传
# 准备SKU图片上传
sku_image_list
=
[]
sku_image_list
=
[]
# 设置超时时间为85秒
timeout_seconds
=
85
start_time
=
time
.
time
()
try
:
try
:
for
sku
in
skus
:
for
sku
in
skus
:
sku_id
=
sku
.
get
(
'sku_id'
)
sku_id
=
sku
.
get
(
'sku_id'
)
...
@@ -225,18 +228,17 @@ async def uploadImageAndVideo(task: dict = None):
...
@@ -225,18 +228,17 @@ async def uploadImageAndVideo(task: dict = None):
check_image_size
(
local_path
)
check_image_size
(
local_path
)
local_path
=
check_image_width_height
(
local_path
,
2
)
local_path
=
check_image_width_height
(
local_path
,
2
)
description_list
.
append
({
md5_key
:
local_path
})
description_list
.
append
({
md5_key
:
local_path
})
# 设置超时时间为60秒
timeout_seconds
=
65
start_time
=
time
.
time
()
# 使用asyncio.wait_for设置超时并行处理所有上传任务
# 使用asyncio.wait_for设置超时并行处理所有上传任务
remaining_time
=
timeout_seconds
-
(
time
.
time
()
-
start_time
)
sku_image_dict
,
image_dict
,
description_dict
=
await
asyncio
.
wait_for
(
sku_image_dict
,
image_dict
,
description_dict
=
await
asyncio
.
wait_for
(
asyncio
.
gather
(
asyncio
.
gather
(
run_in_executor
(
upload_image_by_bytes
,
cookies
,
headers
,
proxies
,
sku_image_list
),
run_in_executor
(
upload_image_by_bytes
,
cookies
,
headers
,
proxies
,
sku_image_list
),
run_in_executor
(
upload_image_by_bytes
,
cookies
,
headers
,
proxies
,
image_list
),
run_in_executor
(
upload_image_by_bytes
,
cookies
,
headers
,
proxies
,
image_list
),
run_in_executor
(
upload_image_by_bytes
,
cookies
,
headers
,
proxies
,
description_list
)
run_in_executor
(
upload_image_by_bytes
,
cookies
,
headers
,
proxies
,
description_list
)
),
),
timeout
=
timeout_seconds
timeout
=
remaining_time
)
)
start_time
=
time
.
time
()
remaining_time
=
timeout_seconds
-
(
time
.
time
()
-
start_time
)
remaining_time
=
timeout_seconds
-
(
time
.
time
()
-
start_time
)
image_list
=
list
(
image_dict
.
values
())
image_list
=
list
(
image_dict
.
values
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment