Completed code to load queue from DB