Refactor work_queue and work_log logic into workunits.py