Skip to content

Commit

Permalink
The blocking version of the FQDN retrieval function
Browse files Browse the repository at this point in the history
  • Loading branch information
jgates108 committed Feb 3, 2025
1 parent fd9df34 commit 2277f63
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/util/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@
// Third-party headers
#include "boost/asio.hpp"

// LSST headers
#include "lsst/log/Log.h"

using namespace std;

namespace {
LOG_LOGGER _log = LOG_GET("lsst.qserv.util.common");
}

namespace lsst::qserv::util {

string get_current_host_fqdn(bool all) {
Expand Down Expand Up @@ -73,4 +80,19 @@ string get_current_host_fqdn(bool all) {
return fqdn;
}

std::string getCurrentHostFqdnBlocking() {
while (true) {
try {
string result = util::get_current_host_fqdn();
if (!result.empty()) {
return result;
}
LOGS(_log, LOG_LVL_ERROR, __func__ << " Empty response for the worker hosts's FQDN.");
} catch (std::runtime_error const& ex) {
LOGS(_log, LOG_LVL_ERROR, __func__ << " Failed to obtain worker hosts's FQDN, ex: " << ex.what());
}
sleep(1);
}
}

} // namespace lsst::qserv::util
6 changes: 6 additions & 0 deletions src/util/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ namespace lsst::qserv::util {
*/
std::string get_current_host_fqdn(bool all = false);

/** Call get_current_host_fqdn(false) repeatedly until a name is gathered.
* Log messages will be printed.
* It will block until successful.
*/
std::string getCurrentHostFqdnBlocking();

template <class Map>
typename Map::mapped_type const& getFromMap(Map const& m, typename Map::key_type const& key,
typename Map::mapped_type const& defValue) {
Expand Down

0 comments on commit 2277f63

Please sign in to comment.