r5 icon indicating copy to clipboard operation
r5 copied to clipboard

Factor out duplicate getOrStartWorker into `BrokerController`

Open trevorgerhardt opened this issue 2 years ago • 0 comments

This code is mostly a duplicate of the code in the BrokerController (in fact it was originally copied from there). Should we abstract this out as a helper method in the broker itself?

   /**
     * Get or start worker.
     */
    public synchronized String getOrStartWorker(WorkerCategory workerCategory, WorkerTags workerTags) {
        String address = getWorkerAddress(workerCategory);
        if (address == null) {
            // There are no workers that can handle this request. Request some.
            createOnDemandWorkerInCategory(workerCategory, workerTags);
        } else {
            // Workers exist in this category, clear out any record that we're waiting for one to start up.
            // FIXME the tracking of which workers are starting up should really be encapsulated using a "start up if needed" method.
            recentlyRequestedWorkers.remove(workerCategory);
        }
        return address;
    }

At the very least, we shouldn't leave the replicated FIXME in two different places.

Originally posted by @trevorgerhardt in https://github.com/conveyal/r5/pull/782#discussion_r836006040

trevorgerhardt avatar Apr 01 '22 01:04 trevorgerhardt