Fixes a race condition which could result in a scheduled item being adde...

...d to the queue twice, or a retry being retried twice.