I have setup an asynchronous python task in a Flask Restful API. The asynchronous task can run for up to several hours. While that long task runs in Celery, it periodically outputs text on the celery terminal. My question: how can I stream the stdout, and monitor the stdout outputs on a web-app.
The basic structure of how I have set up my task in Python is like this:
@celery.task(name='my_long_task')
def my_long_task(arg_1):
proc = subprocess.Popen(f'python xyz.py', shell=True)
def start_background_task():
arg_1 = "my name"
my_long_task.delay(arg_1)
I have explored Flower and programmatically logging Celery tasks, but so far I have not been able to access the "live stream" of the stdout of a celery task. Any suggestions on how to achieve this will be very helpful.