0

I have the current route

@app.route('/as/<keyword>', methods=['GET'])
@cache.memoize(timeout = 30 * 24 * 60 * 60)
def auto_suggest(keyword):
    job = q.enqueue(find_keyword, keyword, timeout = 60 * 60)
    while not job.result:
        time.sleep(1)
    return jsonify(word=job.result)

When I run this on local it works fine since it does not time out. After the function is run once the result is saved into cache and on subsequent reloads it loads instantly. but once I put it on the server when I run the route it times out.

even though the task completes after the time out, when I reload the function it reruns the task instead of calling it from cache.

Is there another way I should be doing this?

nadermx
  • 2,596
  • 7
  • 31
  • 66

1 Answers1

0

I went ahead and solved this by putting the long function in a redis key and calling the key from the route.

@app.route('/as/<keyword>', methods=['GET'])
def auto_suggest(keyword):
    if not redis.get(keyword):
        q.enqueue(find_keyword, keyword, timeout = 60 * 60)
        return jsonify(word=False)
    return jsonify(word=redis.get(keyword))
nadermx
  • 2,596
  • 7
  • 31
  • 66