From 592fa64120e2712c46dd020fbda0c128c69467b7 Mon Sep 17 00:00:00 2001 From: gebele Date: Fri, 12 Jul 2019 10:50:51 +0000 Subject: kill task pid if page is reloaded --- application.rb | 8 ++++++++ views/batch.haml | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/application.rb b/application.rb index 76137b9..0d5da57 100644 --- a/application.rb +++ b/application.rb @@ -221,6 +221,14 @@ get '/prediction/task/?' do task = Task.find(params[:turi].to_s) response['Content-Type'] = "application/json" return JSON.pretty_generate(:percent => task.percent) + elsif params[:ktpid] + begin + Process.kill(9,params[:ktpid].to_i) if !params[:ktpid].blank? + rescue + nil + end + response['Content-Type'] = "application/json" + return JSON.pretty_generate(:ktpid => params[:ktpid]) elsif params[:predictions] task = Task.find(params[:predictions]) pageSize = params[:pageSize].to_i - 1 diff --git a/views/batch.haml b/views/batch.haml index 3f54772..45997bf 100644 --- a/views/batch.haml +++ b/views/batch.haml @@ -1,3 +1,12 @@ +:javascript + // kill task pid if page is reloaded, `false` makes the request synchronous + window.addEventListener('unload', ktpid, false); + function ktpid() { + var client = new XMLHttpRequest(); + client.open("GET", "#{to("/prediction/task?ktpid=#{@pid}")}", false); + client.setRequestHeader("Content-Type", "application/json"); + client.send(null); + }; %div.card %a.btn.btn-outline-info{:href => to("/predict?tpid=#{@pid}")} %span.fa.fa-caret-left{:aria=>{:hidden=>"true"}} -- cgit v1.2.3