You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have implemented a Flask API with a BullMQ Worker to handle report generation. Although the job is successfully added to the queue and the worker appears to be initialized correctly ("Worker is ready and listening for jobs." is logged), the report generation function is never executed.
Relevant Code
The key parts of the code are as follows:
Adding the job to the queue in the Flask API:
@app.route('/generate-report', methods=['POST'])asyncdefgenerate_report():
data=request.get_json()
survey_id=data.get("id")
ifnotsurvey_id:
returnjsonify({"error": "ID missing"}), 400job=awaitqueue.add("generate_report", {"survey_id": survey_id})
logger.info(f"Added job to queue with ID: {job.id}")
returnjsonify({"message": "Task in progress", "task_id": job.id})
Job processing by the Worker:
asyncdefprocess_job(job):
survey_id=job.data.get("survey_id")
logger.info(f"Processing job with survey ID: {survey_id}")
returnawaitgenerate_report_task(survey_id)
Worker Initialization:
asyncdefmain_worker():
try:
logger.info("Initializing worker...")
worker=Worker("generate_reports_queue", process_job)
logger.info("Worker is ready and listening for jobs.")
awaitasyncio.Future() # Keep the worker runningexceptExceptionase:
logger.error(f"Worker error: {e}", exc_info=True)
Expected Behavior
I expected the generate_report_task function to be called and the report to be generated once the job is picked up by the worker.
Observed Behavior
The job is successfully added to the queue.
The message "Worker is ready and listening for jobs." appears in the logs.
However, the generate_report_task function is never called.
Technical Details
Python 3.11
Running on WSL2
Request for Help
I believe the worker is not correctly intercepting jobs from the queue. Any suggestions or troubleshooting tips would be greatly appreciated. Thank you in advance for your help!
The text was updated successfully, but these errors were encountered:
I have implemented a Flask API with a BullMQ Worker to handle report generation. Although the job is successfully added to the queue and the worker appears to be initialized correctly ("Worker is ready and listening for jobs." is logged), the report generation function is never executed.
Relevant Code
The key parts of the code are as follows:
Expected Behavior
I expected the
generate_report_task
function to be called and the report to be generated once the job is picked up by the worker.Observed Behavior
generate_report_task
function is never called.Technical Details
Request for Help
I believe the worker is not correctly intercepting jobs from the queue. Any suggestions or troubleshooting tips would be greatly appreciated. Thank you in advance for your help!
The text was updated successfully, but these errors were encountered: