r5
r5 copied to clipboard
Factor out duplicate getOrStartWorker into `BrokerController`
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