Update scheduler.py

Added query_machine to poll DB for locked machine; Added loop to await agent available status; Moved Machine unlock to post completion.