Factored out isJobEnded.
Moved sleep to after the first check so jobs already ended don't
incur the sleep cost.

Undid specific cancellation check in RemoveAllKeysTask.