title: How do I return flask render_template after the Redis background job is done?
body: <p>I have this web app in a flask where I want to execute some ML and AI algorithms after a form is submitted. I am running the ML and AI algorithms in a background job with the help of Redis and rq ( because I have my app hosted by Heroku and they have this timeout thing where you have to return a response within 30 seconds). After the job is done I would like to get the images made by the algorithms ( some graphs ) and output them in a web page, but I have no idea how to render a template in a job function, and importing the app from the flask app to do that doesn't seem to work. Do you have any ideas on how to solve this?</p>
  
  <p>my code fragment from the flask app that enqueues a job: </p>
  
  <pre><code>def upload():
      from mlsalespred import run_model
      file = request.files['file']
      dffile = pd.read_csv(file)
      job = q.enqueue(run_model, dffile)
      return render_template("waiting.html")
  </code></pre>
  
  <p>my code fragment from the job function:</p>
  
  <pre><code>def run_model(dataFrame):
      - - - - - - - - - - -
      - - some ml stuff - -
      - - - - - - - - - - -
      return render_template("uploaded.html", sales_fig = sales_fig.decode('utf8'), diff_fig = diff_fig.decode('utf8'), pred_fig = pred_fig.decode('utf8') )
  
  </code></pre>
  
  <p>Thanks in advance</p>