23
23
check_newest_search_result ,
24
24
)
25
25
from mcim_sync .cleaner .modrinth import remove_projects
26
- from mcim_sync .fetcher .modrinth import fetch_expired_and_removed_modrinth_data , fetch_all_modrinth_data
26
+ from mcim_sync .fetcher .modrinth import (
27
+ fetch_expired_and_removed_modrinth_data ,
28
+ fetch_all_modrinth_data ,
29
+ )
27
30
from mcim_sync .queues .modrinth import clear_modrinth_all_queues
28
31
from mcim_sync .tasks import create_tasks_pool
29
32
@@ -52,20 +55,20 @@ def refresh_modrinth_with_modify_date() -> bool:
52
55
53
56
# 刷新过期的 modrinth 数据
54
57
log .info ("Start syncing Modrinth expired data..." )
55
- modrinth_pool , modrinth_futures = create_tasks_pool (
58
+ with create_tasks_pool (
56
59
sync_project , # 需要 ProjectDetail 返回值
57
60
modrinth_expired_data ,
58
61
MAX_WORKERS ,
59
62
"refresh_modrinth" ,
60
- )
61
-
62
- projects_detail_info = []
63
- for future in as_completed ( modrinth_futures ):
64
- result = future . result ()
65
- if result :
66
- projects_detail_info . append ( result )
67
- else :
68
- modrinth_pool . shutdown ( )
63
+ ) as modrinth_futures :
64
+ log . info (
65
+ f"All { len ( modrinth_futures ) } tasks submitted, waiting for completion..."
66
+ )
67
+ projects_detail_info = []
68
+ for future in as_completed ( modrinth_futures ) :
69
+ result = future . result ( )
70
+ if result :
71
+ projects_detail_info . append ( result )
69
72
70
73
if config .telegram_bot :
71
74
notification = RefreshNotification (
@@ -85,13 +88,19 @@ def fetch_modrinth_not_found_ids_from_queue():
85
88
project_ids = []
86
89
avaliable_project_ids = check_modrinth_project_ids_available ()
87
90
project_ids .extend (avaliable_project_ids )
88
- log .info (f"Modrinth project ids queue available project_ids: { len (avaliable_project_ids )} " )
91
+ log .info (
92
+ f"Modrinth project ids queue available project_ids: { len (avaliable_project_ids )} "
93
+ )
89
94
avaliable_project_ids = check_modrinth_version_ids_available ()
90
95
project_ids .extend (avaliable_project_ids )
91
- log .info (f"Modrinth version ids queue available project_ids: { len (avaliable_project_ids )} " )
96
+ log .info (
97
+ f"Modrinth version ids queue available project_ids: { len (avaliable_project_ids )} "
98
+ )
92
99
avaliable_project_ids = check_modrinth_hashes_available ()
93
100
project_ids .extend (avaliable_project_ids )
94
- log .info (f"Modrinth hashes queue available project_ids: { len (avaliable_project_ids )} " )
101
+ log .info (
102
+ f"Modrinth hashes queue available project_ids: { len (avaliable_project_ids )} "
103
+ )
95
104
return project_ids
96
105
97
106
@@ -107,22 +116,22 @@ def sync_modrinth_queue() -> bool:
107
116
log .info (f"New project ids: { new_project_ids } , count: { len (new_project_ids )} " )
108
117
109
118
if new_project_ids :
110
- pool , futures = create_tasks_pool (
111
- # sync_project, project_ids, MAX_WORKERS, "modrinth"
112
- sync_project ,
113
- new_project_ids ,
114
- MAX_WORKERS ,
115
- "sync_modrinth_by_queue" , # https://github.com/mcmod-info-mirror/mcim-sync/issues/2
116
- )
117
-
118
- projects_detail_info = []
119
+ with (
120
+ create_tasks_pool (
121
+ # sync_project, project_ids, MAX_WORKERS, "modrinth"
122
+ sync_project ,
123
+ new_project_ids ,
124
+ MAX_WORKERS ,
125
+ "sync_modrinth_by_queue" , # https://github.com/mcmod-info-mirror/mcim-sync/issues/2
126
+ ) as futures
127
+ ):
128
+ projects_detail_info = []
129
+
130
+ for future in as_completed (futures ):
131
+ result = future .result ()
132
+ if result :
133
+ projects_detail_info .append (result )
119
134
120
- for future in as_completed (futures ):
121
- result = future .result ()
122
- if result :
123
- projects_detail_info .append (result )
124
-
125
- pool .shutdown ()
126
135
log .info (f"Modrinth queue sync finished, total: { len (project_ids )} " )
127
136
128
137
# clear queue
@@ -150,20 +159,18 @@ def sync_modrinth_by_search():
150
159
new_project_ids = check_newest_search_result ()
151
160
log .info (f"Modrinth project ids fetched: { len (new_project_ids )} " )
152
161
if new_project_ids :
153
- pool , futures = create_tasks_pool (
162
+ with create_tasks_pool (
154
163
sync_project ,
155
164
new_project_ids ,
156
165
MAX_WORKERS ,
157
166
"sync_modrinth_by_search" ,
158
- )
167
+ ) as futures :
168
+ projects_detail_info = []
169
+ for future in as_completed (futures ):
170
+ result = future .result ()
171
+ if result :
172
+ projects_detail_info .append (result )
159
173
160
- projects_detail_info = []
161
- for future in as_completed (futures ):
162
- result = future .result ()
163
- if result :
164
- projects_detail_info .append (result )
165
-
166
- pool .shutdown ()
167
174
log .info (
168
175
f"Modrinth sync new project by search finished, total: { len (new_project_ids )} "
169
176
)
@@ -200,6 +207,7 @@ def refresh_modrinth_tags():
200
207
log .info ("All Message sent to telegram." )
201
208
return True
202
209
210
+
203
211
def refresh_modrinth_full ():
204
212
"""
205
213
刷新 modrinth 所有数据
@@ -209,26 +217,25 @@ def refresh_modrinth_full():
209
217
modrinth_data = fetch_all_modrinth_data ()
210
218
log .info (f"Modrinth data totally fetched: { len (modrinth_data )} " )
211
219
212
- modrinth_pool , modrinth_futures = create_tasks_pool (
220
+ with create_tasks_pool (
213
221
sync_project , modrinth_data , MAX_WORKERS , "modrinth_refresh_full"
214
- )
215
-
216
- log .info (
217
- f"All { len (modrinth_futures )} tasks submitted, waiting for completion..."
218
- )
222
+ ) as modrinth_futures :
223
+ log .info (
224
+ f"All { len (modrinth_futures )} tasks submitted, waiting for completion..."
225
+ )
219
226
220
- projects_detail_info = []
221
- for future in as_completed (modrinth_futures ):
222
- result = future .result ()
223
- if result :
224
- projects_detail_info .append (result )
225
- else :
226
- modrinth_pool .shutdown ()
227
+ projects_detail_info = []
228
+ for future in as_completed (modrinth_futures ):
229
+ result = future .result ()
230
+ if result :
231
+ projects_detail_info .append (result )
227
232
228
233
success_project_ids = [project .id for project in projects_detail_info if project ]
229
-
234
+
230
235
failed_count = len (modrinth_data ) - len (success_project_ids )
231
- failed_project_ids = [project .id for project in modrinth_data if project .id not in success_project_ids ]
236
+ failed_project_ids = [
237
+ project .id for project in modrinth_data if project .id not in success_project_ids
238
+ ]
232
239
233
240
log .info (
234
241
f"Modrinth full sync finished, total: { len (modrinth_data )} , "
@@ -244,5 +251,5 @@ def refresh_modrinth_full():
244
251
)
245
252
notice .send_to_telegram ()
246
253
log .info ("Modrinth full refresh message sent to telegram." )
247
-
248
- return True
254
+
255
+ return True
0 commit comments