Keep updating Build status in Meilix Generator
One of the problems we faced while working Meilix Generator was to provide user with the status of the custom ISO build in the Meilix Generator web app so we came up with the idea of checking the status of the link generated by the web app. If the link is available the status code would be 200 otherwise it would be 404.
We have used python script for checking the status of URL. For generating URL, we use the tag name which will be used as a variable to generate the URL of the unique event user wants the ISO for and the date will help in generation of link rest of the link remains the same.
tag = os.environ["TRAVIS_TAG"] date = datetime.datetime.now().strftime('%Y%m%d') url=https://github.com/xeon-zolt/meilix/releases/download/"+tag+"/meilix-zesty-"+date+"-i386.iso"
Now we will use urllib for monitoring the status of link.
req = Request(url) try: response = urlopen(req) except HTTPError as e: return('Building Your Iso') except URLError as e: return('We failed to reach the server.') else: return('Build Sucessful : ' + url)
After monitoring the status the next step was to update the status dynamically on the status page.
So we’llll use a status function in the flask app which is used by JavaScript to get status of the link after intervals of time.
Flask :
@app.route('/now') def status_url(): return (status())
Javascript:
<script type ="text/javascript"> let url ="/now" function getstatus(url) { fetch(url).then(function(response){ return response.text() }).then(function(text){ console.log("status",text) document.querySelector("div#status") .innerHTML = text }) } window.onload = function(){ fetch(url).then(function(response){ return response.text() }).then(function(text){ console.log("status",text) document.querySelector("div#status") .innerHTML = text }) window.setInterval(getstatus.bind(null,url),30*1000) } /*setInterval(function,interval in millsecs)*/ </script>
This covers various steps to prompt user whether the build is ready or not.