22import queue
33import threading
44import time
5+ import uuid
56from threading import Lock
67
78
@@ -38,7 +39,7 @@ def add_export_task(self, username, repo_id, workspace_id, dtable_uuid, dtable_n
3839 asset_dir_path = os .path .join ('/asset' , dtable_uuid )
3940 asset_dir_id = seafile_api .get_dir_id_by_path (repo_id , asset_dir_path )
4041
41- task_id = str (int ( time . time () * 1000 ))
42+ task_id = str (uuid . uuid4 ( ))
4243 task = (get_dtable_export_content ,
4344 (username , repo_id , workspace_id , dtable_uuid , asset_dir_id , self .config ))
4445 self .tasks_queue .put (task_id )
@@ -50,7 +51,7 @@ def add_import_task(self, username, repo_id, workspace_id, dtable_uuid, dtable_f
5051 can_use_automation_rules , can_use_workflows , can_use_external_apps , owner , org_id ):
5152 from dtable_events .dtable_io import post_dtable_import_files
5253
53- task_id = str (int ( time . time () * 1000 ))
54+ task_id = str (uuid . uuid4 ( ))
5455 task = (post_dtable_import_files ,
5556 (username , repo_id , workspace_id , dtable_uuid , dtable_file_name , in_storage ,
5657 can_use_automation_rules , can_use_workflows , can_use_external_apps , owner , org_id , self .config ))
@@ -61,7 +62,7 @@ def add_import_task(self, username, repo_id, workspace_id, dtable_uuid, dtable_f
6162 def add_export_dtable_asset_files_task (self , username , repo_id , dtable_uuid , files , files_map = None ):
6263 from dtable_events .dtable_io import get_dtable_export_asset_files
6364
64- task_id = str (int ( time . time () * 1000 ))
65+ task_id = str (uuid . uuid4 ( ))
6566 task = (get_dtable_export_asset_files ,
6667 (username , repo_id , dtable_uuid , files , task_id , files_map ))
6768 self .tasks_queue .put (task_id )
@@ -70,7 +71,7 @@ def add_export_dtable_asset_files_task(self, username, repo_id, dtable_uuid, fil
7071
7172 def add_transfer_dtable_asset_files_task (self , username , repo_id , dtable_uuid , files , files_map , parent_dir , relative_path , replace , repo_api_token , seafile_server_url ):
7273 from dtable_events .dtable_io import get_dtable_transfer_asset_files
73- task_id = str (int ( time . time () * 1000 ))
74+ task_id = str (uuid . uuid4 ( ))
7475 task = (get_dtable_transfer_asset_files ,
7576 (username ,
7677 repo_id ,
@@ -90,7 +91,7 @@ def add_transfer_dtable_asset_files_task(self, username, repo_id, dtable_uuid, f
9091 def add_parse_excel_csv_task (self , username , repo_id , workspace_id , dtable_name , file_type , custom ):
9192 from dtable_events .dtable_io import parse_excel_csv
9293
93- task_id = str (int ( time . time () * 1000 ))
94+ task_id = str (uuid . uuid4 ( ))
9495 task = (parse_excel_csv ,
9596 (username , repo_id , workspace_id , dtable_name , file_type , custom , self .config ))
9697 self .tasks_queue .put (task_id )
@@ -100,7 +101,7 @@ def add_parse_excel_csv_task(self, username, repo_id, workspace_id, dtable_name,
100101 def add_import_excel_csv_task (self , username , repo_id , workspace_id , dtable_uuid , dtable_name , lang ):
101102 from dtable_events .dtable_io import import_excel_csv
102103
103- task_id = str (int ( time . time () * 1000 ))
104+ task_id = str (uuid . uuid4 ( ))
104105 task = (import_excel_csv ,
105106 (username , repo_id , workspace_id , dtable_uuid , dtable_name , lang , self .config ))
106107 self .tasks_queue .put (task_id )
@@ -110,7 +111,7 @@ def add_import_excel_csv_task(self, username, repo_id, workspace_id, dtable_uuid
110111 def add_import_excel_csv_add_table_task (self , username , repo_id , workspace_id , dtable_uuid , dtable_name , lang ):
111112 from dtable_events .dtable_io import import_excel_csv_add_table
112113
113- task_id = str (int ( time . time () * 1000 ))
114+ task_id = str (uuid . uuid4 ( ))
114115 task = (import_excel_csv_add_table ,
115116 (username , repo_id , workspace_id , dtable_uuid , dtable_name , lang , self .config ))
116117 self .tasks_queue .put (task_id )
@@ -120,7 +121,7 @@ def add_import_excel_csv_add_table_task(self, username, repo_id, workspace_id, d
120121 def add_append_excel_csv_append_parsed_file_task (self , username , repo_id , dtable_uuid , file_name , table_name ):
121122 from dtable_events .dtable_io import append_excel_csv_append_parsed_file
122123
123- task_id = str (int ( time . time () * 1000 ))
124+ task_id = str (uuid . uuid4 ( ))
124125 task = (append_excel_csv_append_parsed_file ,
125126 (username , repo_id , dtable_uuid , file_name , table_name ))
126127 self .tasks_queue .put (task_id )
@@ -130,7 +131,7 @@ def add_append_excel_csv_append_parsed_file_task(self, username, repo_id, dtable
130131 def add_append_excel_csv_upload_file_task (self , username , repo_id , file_name , dtable_uuid , table_name , file_type ):
131132 from dtable_events .dtable_io import append_excel_csv_upload_file
132133
133- task_id = str (int ( time . time () * 1000 ))
134+ task_id = str (uuid . uuid4 ( ))
134135 task = (append_excel_csv_upload_file ,
135136 (username , repo_id , file_name , dtable_uuid , table_name , file_type ))
136137 self .tasks_queue .put (task_id )
@@ -139,7 +140,7 @@ def add_append_excel_csv_upload_file_task(self, username, repo_id, file_name, dt
139140
140141 def add_run_auto_rule_task (self , automation_rule_id , username , org_id , dtable_uuid , run_condition , trigger , actions ):
141142 from dtable_events .automations .auto_rules_utils import run_auto_rule_task
142- task_id = str (int ( time . time () * 1000 ))
143+ task_id = str (uuid . uuid4 ( ))
143144 options = {
144145 'run_condition' : run_condition ,
145146 'dtable_uuid' : dtable_uuid ,
@@ -157,7 +158,7 @@ def add_update_excel_csv_update_parsed_file_task(self, username, repo_id, dtable
157158 selected_columns ):
158159 from dtable_events .dtable_io import update_excel_csv_update_parsed_file
159160
160- task_id = str (int ( time . time () * 1000 ))
161+ task_id = str (uuid . uuid4 ( ))
161162 task = (update_excel_csv_update_parsed_file ,
162163 (username , repo_id , dtable_uuid , file_name , table_name , selected_columns ))
163164 self .tasks_queue .put (task_id )
@@ -167,7 +168,7 @@ def add_update_excel_csv_update_parsed_file_task(self, username, repo_id, dtable
167168 def add_update_excel_upload_excel_task (self , username , repo_id , file_name , dtable_uuid , table_name ):
168169 from dtable_events .dtable_io import update_excel_upload_excel
169170
170- task_id = str (int ( time . time () * 1000 ))
171+ task_id = str (uuid . uuid4 ( ))
171172 task = (update_excel_upload_excel ,
172173 (username , repo_id , file_name , dtable_uuid , table_name ))
173174 self .tasks_queue .put (task_id )
@@ -177,7 +178,7 @@ def add_update_excel_upload_excel_task(self, username, repo_id, file_name, dtabl
177178 def add_update_csv_upload_csv_task (self , username , repo_id , file_name , dtable_uuid , table_name ):
178179 from dtable_events .dtable_io import update_csv_upload_csv
179180
180- task_id = str (int ( time . time () * 1000 ))
181+ task_id = str (uuid . uuid4 ( ))
181182 task = (update_csv_upload_csv ,
182183 (username , repo_id , file_name , dtable_uuid , table_name ))
183184 self .tasks_queue .put (task_id )
@@ -187,7 +188,7 @@ def add_update_csv_upload_csv_task(self, username, repo_id, file_name, dtable_uu
187188 def add_import_excel_csv_to_dtable_task (self , username , repo_id , workspace_id , dtable_name , dtable_uuid , file_type , lang ):
188189 from dtable_events .dtable_io import import_excel_csv_to_dtable
189190
190- task_id = str (int ( time . time () * 1000 ))
191+ task_id = str (uuid . uuid4 ( ))
191192 task = (import_excel_csv_to_dtable , (username , repo_id , workspace_id , dtable_name , dtable_uuid , file_type , lang ))
192193 self .tasks_queue .put (task_id )
193194 self .tasks_map [task_id ] = task
@@ -196,7 +197,7 @@ def add_import_excel_csv_to_dtable_task(self, username, repo_id, workspace_id, d
196197 def add_import_excel_csv_to_table_task (self , username , repo_id , workspace_id , file_name , dtable_uuid , file_type , lang ):
197198 from dtable_events .dtable_io import import_excel_csv_to_table
198199
199- task_id = str (int ( time . time () * 1000 ))
200+ task_id = str (uuid . uuid4 ( ))
200201 task = (import_excel_csv_to_table , (username , repo_id , workspace_id , file_name , dtable_uuid , file_type , lang ))
201202 self .tasks_queue .put (task_id )
202203 self .tasks_map [task_id ] = task
@@ -205,7 +206,7 @@ def add_import_excel_csv_to_table_task(self, username, repo_id, workspace_id, fi
205206 def add_update_table_via_excel_csv_task (self , username , repo_id , file_name , dtable_uuid , table_name , selected_columns , file_type ):
206207 from dtable_events .dtable_io import update_table_via_excel_csv
207208
208- task_id = str (int ( time . time () * 1000 ))
209+ task_id = str (uuid . uuid4 ( ))
209210 task = (update_table_via_excel_csv , (username , repo_id , file_name , dtable_uuid , table_name , selected_columns , file_type ))
210211 self .tasks_queue .put (task_id )
211212 self .tasks_map [task_id ] = task
@@ -214,7 +215,7 @@ def add_update_table_via_excel_csv_task(self, username, repo_id, file_name, dtab
214215 def add_append_excel_csv_to_table_task (self , username , repo_id , file_name , dtable_uuid , table_name , file_type ):
215216 from dtable_events .dtable_io import append_excel_csv_to_table
216217
217- task_id = str (int ( time . time () * 1000 ))
218+ task_id = str (uuid . uuid4 ( ))
218219 task = (append_excel_csv_to_table , (username , repo_id , file_name , dtable_uuid , table_name , file_type ))
219220 self .tasks_queue .put (task_id )
220221 self .tasks_map [task_id ] = task
@@ -233,7 +234,7 @@ def query_status(self, task_id):
233234 def convert_page_to_pdf (self , dtable_uuid , page_id , row_id , access_token , session_id ):
234235 from dtable_events .dtable_io import convert_page_to_pdf
235236
236- task_id = str (int ( time . time () * 1000 ))
237+ task_id = str (uuid . uuid4 ( ))
237238 task = (convert_page_to_pdf ,
238239 (dtable_uuid , page_id , row_id , access_token , session_id ))
239240 self .tasks_queue .put (task_id )
@@ -244,7 +245,7 @@ def convert_page_to_pdf(self, dtable_uuid, page_id, row_id, access_token, sessio
244245 def add_import_table_from_base_task (self , context ):
245246 from dtable_events .dtable_io .import_table_from_base import import_table_from_base
246247
247- task_id = str (int ( time . time () * 1000 ))
248+ task_id = str (uuid . uuid4 ( ))
248249 task = (import_table_from_base , (context ,))
249250 self .tasks_queue .put (task_id )
250251 self .tasks_map [task_id ] = task
@@ -254,7 +255,7 @@ def add_import_table_from_base_task(self, context):
254255 def add_import_common_dataset_task (self , context ):
255256 from dtable_events .dtable_io .import_sync_common_dataset import import_common_dataset
256257
257- task_id = str (int ( time . time () * 1000 ))
258+ task_id = str (uuid . uuid4 ( ))
258259 task = (import_common_dataset , (context , self .config ))
259260 self .tasks_queue .put (task_id )
260261 self .tasks_map [task_id ] = task
@@ -273,7 +274,7 @@ def add_sync_common_dataset_task(self, context):
273274 return None , 'syncing'
274275 self .dataset_sync_ids .add (dataset_sync_id )
275276
276- task_id = str (int ( time . time () * 1000 ))
277+ task_id = str (uuid . uuid4 ( ))
277278 task = (sync_common_dataset , (context , self .config ))
278279 self .tasks_queue .put (task_id )
279280 self .tasks_map [task_id ] = task
@@ -283,7 +284,7 @@ def add_sync_common_dataset_task(self, context):
283284 def add_convert_view_to_execl_task (self , dtable_uuid , table_id , view_id , username , id_in_org , permission , name , repo_id , is_support_image ):
284285 from dtable_events .dtable_io import convert_view_to_execl
285286
286- task_id = str (int ( time . time () * 1000 ))
287+ task_id = str (uuid . uuid4 ( ))
287288 task = (convert_view_to_execl , (dtable_uuid , table_id , view_id , username , id_in_org , permission , name , repo_id , is_support_image ))
288289 self .tasks_queue .put (task_id )
289290 self .tasks_map [task_id ] = task
@@ -293,7 +294,7 @@ def add_convert_view_to_execl_task(self, dtable_uuid, table_id, view_id, usernam
293294 def add_convert_table_to_execl_task (self , dtable_uuid , table_id , username , permission , name , repo_id , is_support_image ):
294295 from dtable_events .dtable_io import convert_table_to_execl
295296
296- task_id = str (int ( time . time () * 1000 ))
297+ task_id = str (uuid . uuid4 ( ))
297298 task = (convert_table_to_execl , (dtable_uuid , table_id , username , permission , name , repo_id , is_support_image ))
298299 self .tasks_queue .put (task_id )
299300 self .tasks_map [task_id ] = task
@@ -302,7 +303,7 @@ def add_convert_table_to_execl_task(self, dtable_uuid, table_id, username, permi
302303
303304 def add_app_users_sync_task (self , dtable_uuid , app_name , app_id , table_name , table_id , username ):
304305 from dtable_events .dtable_io import app_user_sync
305- task_id = str (int ( time . time () * 1000 ))
306+ task_id = str (uuid . uuid4 ( ))
306307 task = (app_user_sync , (dtable_uuid , app_name , app_id , table_name , table_id , username , self .config ))
307308 self .tasks_queue .put (task_id )
308309 self .tasks_map [task_id ] = task
@@ -329,6 +330,9 @@ def handle_task(self):
329330
330331 task = self .tasks_map .get (task_id )
331332 try :
333+ if type (task [0 ]).__name__ != 'function' :
334+ continue
335+
332336 task_info = task_id + ' ' + str (task [0 ])
333337 self .current_task_info [task_id ] = task_info
334338 dtable_io_logger .info ('Run task: %s' % task_info )
0 commit comments