Skip to content

Commit

Permalink
3d-beacons handling, proper error page
Browse files Browse the repository at this point in the history
  • Loading branch information
mhekkel committed Jan 10, 2024
1 parent f4f7423 commit 77ad9a3
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 56 deletions.
41 changes: 41 additions & 0 deletions docroot/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html SYSTEM "about:legacy-compat">

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:z2="http://www.hekkelman.com/libzeep/m2" lang="nl">

<head z2:replace="~{head::head(~{::title},~{::head/script})}">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />

<title>AlphaFill - Error</title>
</head>

<body>
<header z2:replace="header::top('error')"></header>

<div class="container">

<div class="container-fluid mt-5">
<div class="alert alert-danger" role="alert">
<span z2:if="${error.nr}" class="error-nr" z2:text="${error.nr}"></span>
<span class="error-head-text" z2:text="${error.head}"></span>
</div>
</div>

<div class="container-fluid mt-5">
<p class="error-main-text" z2:text="${error.description}"></p>
<p z2:if="${error.message and error.message != error.description}" z2:text="${error.message}"></p>
</div>

<div class="container-fluid mt-5">
<ul class="error-info">
<li z2:if="${error.request.method}">Method: <em z2:text="${error.request.method}"></em></li>
<li z2:if="${error.request.uri}">URI: <em z2:text="${error.request.uri}"></em></li>
<li z2:if="${error.request.username}">Username: <em z2:text="${error.request.username}"></em></li>
</ul>
</div>
</div>

<footer z2:replace="~{footer::content}"></footer>
</body>

</html>
2 changes: 1 addition & 1 deletion docroot/wait.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h2 class="text-center fw-bold mb-5">AlphaFold models enriched with ligands and

<p class="status unknown">Your entry is not known, please try to resubmit.</p>

<p class="status queued">Your entry is currently queued for processing</p>
<p class="status queued">Your entry is queued for processing</p>

<div class="status running">
<p class="mb-3">Your entry is currently being processed</p>
Expand Down
93 changes: 38 additions & 55 deletions src/data-service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ int data_service::rebuild(const std::string &db_user, const fs::path &db_dir)
if (thread_count < 1)
thread_count = 1;

for (int i = 0; i < thread_count; ++i)
for (size_t i = 0; i < thread_count; ++i)
{
tg.emplace_back([&q1, &q2, &ep]()
{
{
for (;;)
{
auto f = q1.pop();
Expand All @@ -373,15 +373,14 @@ int data_service::rebuild(const std::string &db_user, const fs::path &db_dir)
}
}

q1.push({});
});
q1.push({}); });
}

for (auto &f : files)
{
if (ep)
std::rethrow_exception(ep);

q1.push(std::move(f));
}

Expand Down Expand Up @@ -586,7 +585,7 @@ void data_service::process_queued(const std::filesystem::path &xyzin, const std:
std::error_code ec;

if (not fs::exists(xyzin, ec))
throw std::runtime_error("Input file does not exist");
throw std::runtime_error("Input file '" + xyzin.string() + "' does not exist");

cif::file f(xyzin);
if (f.empty())
Expand Down Expand Up @@ -619,49 +618,14 @@ void data_service::process_queued(const std::filesystem::path &xyzin, const std:
fs::remove(m_work_dir / xyzin.filename(), ec);
if (ec)
std::cerr << "Error removing input file from work dir: " << ec.message() << '\n';

// int pid = fork();

// if (pid < 0)
// throw std::runtime_error("Could not fork: "s + std::strerror(errno));

// if (pid == 0) // child
// {
// try
// {
// auto metadata = alphafill(f.front(), data_service_progress{ m_progress });

// f.save(xyzout);

// std::ofstream metadataFile(jsonout);
// metadataFile << metadata;

// exit(0);
// }
// catch (const std::exception &ex)
// {
// std::ofstream errorFile(m_out_dir / ("CS-" + next + ".error"));
// errorFile << ex.what() << '\n';
// exit(1);
// }
// }

// int status = 0;
// int err = waitpid(pid, &status, 0);

// if (err != 0)
// throw std::runtime_error("Wait failed with error "s + std::strerror(errno));

// if (WIFEXITED(status) and WEXITSTATUS(status) != 0)
// throw std::runtime_error("Alphafill terminated with exit status " + std::to_string(WEXITSTATUS(status)));

// if (WIFSIGNALED(status))
// throw std::runtime_error("Alphafill terminated with signal " + std::to_string(WTERMSIG(status)));
}

void data_service::run()
{
using namespace std::literals;
using namespace date;
using namespace std::chrono;

std::regex rx(R"(((?:AF|CS)-.+?)(?:\.cif\.gz))");

for (;;)
Expand Down Expand Up @@ -691,17 +655,28 @@ void data_service::run()

if (xyzin.empty())
continue;

paein = xyzin;
paein.replace_extension().replace_extension("pae.gz");
if (not fs::exists(paein, ec))
paein.clear();
}
else if (next == "stop")
break;
else
{
xyzin = m_in_dir / (next + ".cif.gz");

// Skip if it does not exist
if (not fs::exists(xyzin))
{
std::clog << system_clock::now() << " requested ID '" << next << "' does not resolve to filename (tried: " << xyzin.string() << ")\n";
continue;
}

paein = xyzin;

if (paein.extension() == ".gz")
paein.replace_extension();
if (paein.extension() == ".cif")
paein.replace_extension("pae.gz");
}

const auto &[type, afId, chunkNr, version] = parse_af_id(next);
fs::path jsonout = file_locator::get_metadata_file(type, afId, chunkNr, version);
fs::path xyzout = file_locator::get_structure_file(type, afId, chunkNr, version);
Expand All @@ -719,10 +694,12 @@ void data_service::run()

try
{
std::clog << system_clock::now() << ' ' << "process: " << xyzin.string() << '\n';
process_queued(xyzin, paein, xyzout, jsonout);
}
catch (const std::exception &ex)
{
std::clog << system_clock::now() << ' ' << ex.what() << '\n';
std::ofstream errorFile(m_out_dir / (next + ".error"));
print_what(errorFile, ex);
}
Expand Down Expand Up @@ -901,6 +878,8 @@ void data_service::queue_3d_beacon_request(const std::string &id)

void data_service::run_3db()
{
using namespace date;
using namespace std::chrono;
using namespace std::literals;

for (;;)
Expand All @@ -920,15 +899,13 @@ void data_service::run_3db()
auto &&[filename, data, pae] = fetch_from_afdb(id);

if (filename.extension() == ".cif")
filename.replace_extension("");

const auto &[type, af_id, chunk, version] = parse_af_id(filename);
filename.replace_extension();

auto outfile = file_locator::get_structure_file(af_id, chunk, version);
auto outfile = m_in_dir / (filename.string() + ".cif.gz");

std::lock_guard<std::mutex> lock(m_mutex);

cif::gzio::ofstream out(m_in_dir / outfile.filename());
cif::gzio::ofstream out(outfile);
if (not out.is_open())
throw std::runtime_error("Could not create temporary file");

Expand All @@ -937,7 +914,11 @@ void data_service::run_3db()

if (not pae.empty())
{
auto paefile = m_in_dir / (outfile.filename().replace_extension().replace_extension("pae.gz"));
auto paefile = outfile;
if (paefile.extension() == ".gz")
paefile.replace_extension();
if (paefile.extension() == ".cif")
paefile.replace_extension("pae.gz");

cif::gzio::ofstream out(m_in_dir / paefile.filename());
if (not out.is_open())
Expand All @@ -947,6 +928,8 @@ void data_service::run_3db()
out.close();
}

std::clog << system_clock::now() << " 3d-beacons requested file " << std::quoted(outfile.string()) << '\n';

m_queue.push(filename.string());
}
catch (const std::exception &ex)
Expand Down

0 comments on commit 77ad9a3

Please sign in to comment.