@m_rahman here you have another example of looping until a job is finished:
Medium: “Loop until a Job is Finished”