Refactor worker#run to prepare fix for #222

Break up worker#run into smaller methods and give each a meaningful
name so it's easier to figure out what it's doing and allow code reuse.

Collapse duplicate if constructs.
Let worker wait for running tasks to complete.

If

- running tasks is non-empty, then another worker is running my tasks
- n_pending_tasks is non-zero, then I have something to do after she is done

And I shall wait for `wait_interval` seconds (with random jitter).

This adds the following configuration options:

- worker-keep-alive [boolean]
- worker-wait-interval [int]
Merge pull request #225 from jimjh/worker-wait

Let worker wait for tasks running on other workers to complete.