Skip to content

Commit

Permalink
Merge pull request #91 from UM-Bridge/hpc-fix-no-url-dir
Browse files Browse the repository at this point in the history
Fix load balancer crash when URL directory is missing
  • Loading branch information
linusseelinger authored Nov 19, 2024
2 parents 660d146 + 1f81bec commit 0464193
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions hpc/LoadBalancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
#include <string>


void clear_url(const std::string& directory) {
void clear_url(const std::filesystem::path& directory) {
if (!std::filesystem::exists(directory)) {
return;
}

for (auto& file : std::filesystem::directory_iterator(directory)) {
if (std::regex_match(file.path().filename().string(), std::regex("url-\\d+\\.txt"))) {
std::filesystem::remove(file);
Expand Down Expand Up @@ -44,7 +48,8 @@ std::string get_arg(const std::vector<std::string>& args, const std::string& arg


int main(int argc, char* argv[]) {
clear_url("urls");
const std::string url_directory = "urls";
clear_url(url_directory);

// Process command line args
std::vector<std::string> args(argv + 1, argv + argc);
Expand Down Expand Up @@ -93,7 +98,7 @@ int main(int argc, char* argv[]) {
// Only filesystem communication is implemented. May implement network-based communication in the future.
// Directory which stores URL files and polling cycle currently hard-coded.
std::unique_ptr<JobCommunicatorFactory> comm_factory
= std::make_unique<FilesystemCommunicatorFactory>("urls", std::chrono::milliseconds(500));
= std::make_unique<FilesystemCommunicatorFactory>(url_directory, std::chrono::milliseconds(500));

// Location of job scripts and naming currently hard-corded.
JobScriptLocator locator {script_dir, "job.sh", "job_", ".sh"};
Expand Down

0 comments on commit 0464193

Please sign in to comment.