fix for import thread

This commit is contained in:
rulingcom 2025-07-02 22:51:28 +08:00
parent ada9e05f51
commit 9cee46cd13
2 changed files with 26 additions and 5 deletions

View File

@ -171,13 +171,16 @@ end
end
Rails.logger.info "rake universal_table_tasks:import[#{tmp_path},#{table_id},#{site_locales}]"
# Call the Rake task with file path
system("rake universal_table_tasks:import[#{tmp_path},#{table_id},#{site_locales}]")
Thread.new do
system("rake universal_table_tasks:import[#{tmp_path},#{table_id},#{site_locales}] >> #{Rails.root}/log/rake.log &")
end
render json: {
success: true,
totalCount: sheet.count - 3,
id: table.id.to_s
}.to_json
end
def new_entry

View File

@ -37,6 +37,12 @@
<br />
<div style="text-align: center;">Importing <span class="current-number">0</span> / <span class="total-number">0</span></div>
</div>
<div id="import-complete-zone" style="text-align: center; display:none;">
<span class="msg">Imported successfully!!!</span>
</div>
<div id="import-error-zone" style="text-align: center; display:none;">
<span class="msg"></span>
</div>
</div>
<div class="modal-footer">
<button class="btn" id="import-modal-close-btn" style="display:none;" data-dismiss="modal" aria-hidden="true">Close</button>
@ -48,7 +54,10 @@
checkForImportThread = null,
importWaitZone = $("#import-wait-zone"),
importModalBtn = $("#import-modal-close-btn"),
importCompleteZone = $("#import-complete-zone"),
importErrorZone = $("#import-error-zone"),
currentNumber = importWaitZone.find(".current-number");
totalNumber = importWaitZone.find(".total-number")
processManager = new ProcessManager();
$("form.import_from_excel_form").on("submit",function(){
var form = this;
@ -57,11 +66,16 @@
importModal.modal("show");
importWaitZone.show();
importModalBtn.hide();
importErrorZone.hide();
importCompleteZone.hide();
totalNumber.text("0");
currentNumber.text("0");
importWaitZone.find("img").show();
$(this).ajaxSubmit({
dataType : "json",
success : function(data){
if(data.success){
importWaitZone.find(".total-number").text(data.totalCount);
totalNumber.text(data.totalCount);
checkForThread = new Process(function(){
$.ajax({
url : "/admin/universal_tables/checkforimportthread",
@ -72,17 +86,21 @@
currentNumber.text(threadData.currentCount)
if(threadData.currentCount >= threadData.totalCount){
checkForThread.kill();
importWaitZone.find(".msg").text("Imported successfully!!!");
importWaitZone.hide();
importCompleteZone.show();
importWaitZone.find("img").hide();
importModalBtn.show();
}
})
})
checkForThread.setTimeInterval(1000);
checkForThread.setTimeInterval(2000);
checkForThread.setRepeat(Process.CONSTANTS.REPEAT_INFINITE);
processManager.queue(checkForThread);
}else{
importWaitZone.find(".msg").text(data.msg)
importWaitZone.hide();
importErrorZone.show();
importModalBtn.show();
importErrorZone.find(".msg").text(data.msg);
}
form.reset();
}