From d3bbd3da3552b8585865520782396e53dffb78f4 Mon Sep 17 00:00:00 2001 From: Marco De Donno Date: Sun, 10 Jun 2018 00:40:50 +0200 Subject: [PATCH] Check if the process function is done (via a file created by the process function) --- app/app.js | 24 ++++++++++++++++++++++++ functions.py | 6 ++++++ module.py | 14 ++++++++++++++ templates/ui.html | 3 ++- 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/app/app.js b/app/app.js index ff8860d..1a4c6ef 100644 --- a/app/app.js +++ b/app/app.js @@ -100,3 +100,27 @@ $.ajax( { $( '#version' ).text( " - " + d.data ); } } ); + +var check_is_done = function() +{ + $.ajax( { + url: baseurl + '/done/' + uuid, + type: "GET", + dataType: 'json', + + success: function( d ) + { + if( d.error == false ) + toastr.success( 'Processing done' ); + else + setTimeout( check_is_done, 500 ); + }, + error: function( d ) + { + setTimeout( check_is_done, 500 ); + } + } ); +} + +toastr.info( "Processing file" ); +setTimeout( check_is_done, 2000 ); diff --git a/functions.py b/functions.py index 36d171d..7ada4a8 100644 --- a/functions.py +++ b/functions.py @@ -119,3 +119,9 @@ def process( infile, wd, filename ): wd + "/" + h + "/tenprint_card_back.png", dpi = ( res, res ) ) + + ############################################################################ + # Write to the end file + + with open( wd + "/" + h + "/done.txt", "w+" ) as fp: + fp.write( "done" ) diff --git a/module.py b/module.py index 5abfd8c..fd7c92b 100644 --- a/module.py +++ b/module.py @@ -222,6 +222,20 @@ def get_archive( uuid ): return send_file( io, attachment_filename = filename + ".zip", as_attachment = True ) + +@api.route( baseurl + '/done/' ) +def is_done( uuid ): + iphash = hashlib.md5( get_ip()[ 1 ] ).hexdigest() + try: + return jsonify( { + 'error': False, + 'isdone': os.path.isfile( UPLOAD_FOLDER + "/" + iphash + "/" + uuid + "/done.txt" ) + } ) + except: + return jsonify( { + 'error': True + } ) + @api.route( baseurl + "/ip" ) def getip(): c, ip = get_ip() diff --git a/templates/ui.html b/templates/ui.html index c7b6426..ff3dacc 100644 --- a/templates/ui.html +++ b/templates/ui.html @@ -1,8 +1,9 @@ - + +