The worker job runner

The worker's StartJob implementation is slightly more complicated as we need to load the vertices and edges that correspond to the UUID range assigned to us by the master node. Fortunately, we have already written all of the required bits of code in Chapter 11, Splitting Monoliths into Microservices, so we can just go ahead and invoke the loading functions with the appropriate arguments:

The CompleteJob method contains the necessary logic for updating the Links 'R' Us document index with the fresh PageRank scores that we just calculated. Let's take a look at its implementation:

The preceding block of code for persisting the calculation results should seem familiar to you as it has been copied verbatim from Chapter 11, Splitting Monoliths into Microservices. The Scores convenience method iterates the graph vertices and invokes the persistScore callback with the vertex ID and PageRank score as arguments.

The persistScore callback (shown as follows) is a simple wrapper for mapping the vertex ID into a UUID value and calling the UpdateScore method of the Links 'R' Us document index component:

Similar to the master job runner implementation, the worker's AbortJob method is also an empty stub. To keep our implementation as lean as possible, we won't bother rolling back any already persisted score changes if any of the other workers fails after the local worker has already completed the job. Since the PageRank scores are periodically re-calculated, we expect them to be eventually consistent.