danverbraganza/pyres — comment on commit 272862d7cfb581c39fa336b93035b534310abca4
File:  line 0
By danverbraganza:

The code for prune_dead_workers gets objects of type Worker by

all_workers = Worker.all(self.resq)

`Worker.all()` in turn calls `Worker.find()`, which used to call the Worker constructor. By default, the
worker constructor assigns the worker object the hostname and pid of the calling process (current
behaviour in master, maintained in this revision if pid and hostame are omitted. The changes in
`Worker.__init__()` allow for any code that creates workers to set the pid and hostname for the worker object.

This is especially useful if we're creating Worker objects by reading the redis server, since they might
possibly refer to remote objects, and so we need to set the pid/hostname externally.

That way,

bits = worker_id.split(':')
worker = cls(queues, resq, pid=bits[1],
hostname=bits[0])

I'm actually not too happy about this snippet, but it works as long as the __name of the worker__
itself does not have any colons. A better option would be if worker_id was a tuple (or namedtuple
) of (hostname, pid), but that would be a more involved change. Also, the variable name `bits` is pretty
misleading, and will be changed if you think there is value in this commit.