The current stack will use Redis Queue to handle our requests, the workflow is expected to be as bellow:
from flask import Flask, request, jsonify
from rq import Queue
from redis import Redis
from time import sleep
app = Flask(__name__)
redis_conn = Redis()
q = Queue(connection=redis_conn)
def background_task(data):
"""Simulate a long-running task."""
sleep(300) # Simulates a 5-minute task
return f"Processed {data}"
@app.route('/submit', methods=['POST'])
def submit():
"""Receive data from the front end and enqueue the task."""
data = request.get_json()
job = q.enqueue(background_task, data)
return jsonify({'job_id': job.id, 'status': 'submitted'})
if __name__ == '__main__':
app.run(debug=True)
This task is about research the way to install Redis and run it on localhost and document the process of doing that.
The current stack will use Redis Queue to handle our requests, the workflow is expected to be as bellow: