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
0095c18e
Commit
0095c18e
authored
Jul 18, 2025
by
baiquan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(shop): 重构任务处理逻辑并优化任务类型判断- 使用 TaskType 枚举替代硬编码的数字,提高代码可读性
- 根据任务类型优化睡眠时间,提高处理效率 - 添加对未知任务类型的处理,增强代码健壮性
parent
a5f07d1d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
3 deletions
+8
-3
shop.py
+8
-3
No files found.
shop.py
View file @
0095c18e
...
...
@@ -138,7 +138,7 @@ def run_sync_shop(task):
async
def
handle_task
(
task
):
"""处理单个任务,根据类型分发"""
type_
=
task
.
get
(
'type'
,
-
1
)
if
type_
==
1
:
if
type_
==
TaskType
.
DOUDIAN_SHOP_LOGIN
:
# 同步店铺任务 - 使用线程池执行
with
concurrent
.
futures
.
ThreadPoolExecutor
(
max_workers
=
INNER_MAX_WORKERS
)
as
inner_executor
:
future
=
inner_executor
.
submit
(
run_sync_shop
,
task
)
...
...
@@ -148,7 +148,7 @@ async def handle_task(task):
logger
.
error
(
f
"同步店铺任务超时: {task}"
)
except
Exception
as
e
:
logger
.
error
(
f
"同步店铺任务异常: {e}"
)
elif
type_
==
2
:
elif
type_
==
TaskType
.
DOUDIAN_UPLOAD_IMAGE_AND_VIDEO
:
# 上传图片和视频任务 - 使用线程池执行
with
concurrent
.
futures
.
ThreadPoolExecutor
(
max_workers
=
INNER_MAX_WORKERS
)
as
inner_executor
:
future
=
inner_executor
.
submit
(
run_upload_image_and_video
,
task
)
...
...
@@ -228,4 +228,9 @@ if __name__ == '__main__':
sys
.
exit
(
0
)
while
True
:
asyncio
.
run
(
run
(
task_type
))
time
.
sleep
(
10
)
if
task_type
==
TaskType
.
DOUDIAN_SHOP_LOGIN
:
time
.
sleep
(
10
)
elif
task_type
==
TaskType
.
DOUDIAN_UPLOAD_IMAGE_AND_VIDEO
:
time
.
sleep
(
1
)
else
:
time
.
sleep
(
5
)
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